PaddlePaddle / PaddleDetection

Object Detection toolkit based on PaddlePaddle. It supports object detection, instance segmentation, multiple object tracking and real-time multi-person keypoint detection.
Apache License 2.0
12.71k stars 2.87k forks source link

PP-YOLOE有没有试验过SIoU Loss(SCYLLA-IoU Loss)? #6070

Closed lixiangMindSpore closed 2 years ago

lixiangMindSpore commented 2 years ago

问题描述 Please describe your issue

PP-YOLOE有没有试验过SIoU Loss(SCYLLA-IoU Loss)?该损失函数号称在COCO数据集上涨点2.4-3.6,论文:https://arxiv.org/pdf/2205.12740.pdf e1b2af3dab9b1e7190a7fd98d2934a0

qingqing01 commented 2 years ago

感谢建议! 后续可以尝试下,您也可以尝试、贡献进来!

WongKinYiu commented 2 years ago

simplify angle loss and start training on yolor

angle loss: 1 - 2 sin^2 (arcsin(sin(\alpha)) - \pi/4) 可以直接寫做 1 - 2 sin^2 (\alpha) - \pi/4) 等於 cos(2 \alpha - \pi/2) 等於 sin(2 \alpha) 等於 2 sin(\alpha) cos(\alpha)

論文中有些符號重複使用, 先依CIoU等loss知識判斷, 待交叉驗證後, 若有效再來分享結果.

WongKinYiu commented 2 years ago

目前跑起來和ciou差不多, 另外有找到一些實現 https://github.com/xialuxi/yolov5-car-plate

lixiangMindSpore commented 2 years ago

目前跑起來和ciou差不多, 另外有找到一些實現 https://github.com/xialuxi/yolov5-car-plate

你有SIoU的源代码?

WongKinYiu commented 2 years ago

沒有, 照論文實現.

lixiangMindSpore commented 2 years ago

沒有, 照論文實現.

代码方便发一下吗?

WongKinYiu commented 2 years ago

目前效果和論文寫的差很多, 得再確認正確性.

WongKinYiu commented 2 years ago

是, 論文裡有個比較ciou和siou的圖. scylla-net本身應該還好, 從內文的描述推測, 他展示的應該是batch 32的推論時間.

jimmyflycv commented 2 years ago

目前跑起來和ciou差不多, 另外有找到一些實現 https://github.com/xialuxi/yolov5-car-plate

I have got simillar conclusion on my pvt dataset, no improvement with siou. I guess the paper should include ablation results on public models instead of a new model. Besides, i have already tried pvt designed loss funcion simillar to siou last month and get no improvement on coco.

sdreamforchen commented 2 years ago

是, 論文裡有個比較ciou和siou的圖. scylla-net本身應該還好, 從內文的描述推測, 他展示的應該是batch 32的推論時間.

哎。我也打算下一个尝试这个SIou的,原理上貌似还可以的。 不知道这样如何,先训练一个baseline或其他。只改这个IOU相关的,把训练好的权重作为pretrain-weights输入进去,这样可以减少训练的epoch。lr估计得设计小一点才行。 不知道你打算怎么做

wilile26811249 commented 2 years ago

目前效果和論文寫的差很多, 得再確認正確性.

@WongKinYiu 可以請問一下你跑的結果如何嗎? 我剛開始跑SIOU的訓練,目前看起來幾乎跟CIOU一模一樣,雖然還沒有跑完,但感受不到論文中的提升。

WongKinYiu commented 2 years ago

在yolor上最後跑出來SIoU比CIoU低了0.2~0.3% AP (測過三種implementation), 係數也測過{2,4,6}, 效果與CIoU比較都沒有提升.

補充: 在係數4的設定下, 前面80個epoch大概比CIoU高0.2, 後面就反超了.

wilile26811249 commented 2 years ago

了解 看起來落差不小 我目前係數是設定成4在跑訓練,如果有什麼結果,我再通知你。 謝謝

sdreamforchen commented 2 years ago

YOLOE改成CIOU会有提升不呢?感谢

---原始邮件--- 发件人: "Kin-Yiu, @.> 发送时间: 2022年6月9日(周四) 下午3:06 收件人: @.>; 抄送: @.**@.>; 主题: Re: [PaddlePaddle/PaddleDetection] PP-YOLOE有没有试验过SIoU Loss(SCYLLA-IoU Loss)? (Issue #6070)

在yolor上最後跑出來SIoU比CIoU低了0.2~0.3% AP (測過三種implementation), 係數也測過{2,4,6}, 效果與CIoU比較都沒有提升.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

nemonameless commented 2 years ago

https://github.com/PaddlePaddle/PaddleDetection/pull/6312 SIoU merged,实验中。

sdreamforchen commented 2 years ago

6312 SIoU merged,实验中。

您好,测试结果出来了吗

sdreamforchen commented 2 years ago

@register @serializable class SIoULoss(object): def init(self, box_format='xyxy', iou_type='siou', reduction='none', eps=1e-7): """ Setting of the class. Args: box_format: (string), must be one of 'xywh' or 'xyxy'. iou_type: (string), can be one of 'ciou', 'diou', 'giou' or 'siou' reduction: (string), specifies the reduction to apply to the output, must be one of 'none', 'mean','sum'. eps: (float), a value to avoid divide by zero error. """ self.box_format = box_format self.iou_type = iou_type.lower() self.reduction = reduction self.eps = eps

def __call__(self, box1, box2):
    """ calculate iou. box1 and box2 are paddle tensor with shape [M, 4] and [Nm 4].
    """
    #box2 = box2.T
    if self.box_format == 'xyxy':
        b1_x1, b1_y1, b1_x2, b1_y2 = box1[0], box1[1], box1[2], box1[3]
        b2_x1, b2_y1, b2_x2, b2_y2 = box2[0], box2[1], box2[2], box2[3]
    elif self.box_format == 'xywh':
        b1_x1, b1_x2 = box1[0] - box1[2] / 2, box1[0] + box1[2] / 2
        b1_y1, b1_y2 = box1[1] - box1[3] / 2, box1[1] + box1[3] / 2
        b2_x1, b2_x2 = box2[0] - box2[2] / 2, box2[0] + box2[2] / 2
        b2_y1, b2_y2 = box2[1] - box2[3] / 2, box2[1] + box2[3] / 2

    # Intersection area
    inter = paddle.clip((paddle.minimum(b1_x2, b2_x2) - paddle.maximum(b1_x1, b2_x1)),0) * \
            paddle.clip((paddle.minimum(b1_y2, b2_y2) - paddle.maximum(b1_y1, b2_y1)),0)

    # Union Area
    w1, h1 = b1_x2 - b1_x1, b1_y2 - b1_y1 + self.eps
    w2, h2 = b2_x2 - b2_x1, b2_y2 - b2_y1 + self.eps
    union = w1 * h1 + w2 * h2 - inter + self.eps
    iou = inter / union

    cw = paddle.maximum(b1_x2, b2_x2) - paddle.minimum(b1_x1, b2_x1)  # convex width
    ch = paddle.maximum(b1_y2, b2_y2) - paddle.minimum(b1_y1, b2_y1)  # convex height
    if self.iou_type == 'giou':
        c_area = cw * ch + self.eps  # convex area
        iou = iou - (c_area - union) / c_area
    elif self.iou_type in ['diou', 'ciou']:
        c2 = cw ** 2 + ch ** 2 + self.eps  # convex diagonal squared
        rho2 = ((b2_x1 + b2_x2 - b1_x1 - b1_x2) ** 2 +
                (b2_y1 + b2_y2 - b1_y1 - b1_y2) ** 2) / 4  # center distance squared
        if self.iou_type == 'diou':
            iou = iou - rho2 / c2
        elif self.iou_type == 'ciou':
            v = (4 / math.pi ** 2) * paddle.pow(math.atan(w2 / h2) - math.atan(w1 / h1), 2)
            with paddle.no_grad():
                alpha = v / (v - iou + (1 + self.eps))
            iou = iou - (rho2 / c2 + v * alpha)
    elif self.iou_type == 'siou':
        # SIoU Loss https://arxiv.org/pdf/2205.12740.pdf
        s_cw = (b2_x1 + b2_x2 - b1_x1 - b1_x2) * 0.5
        s_ch = (b2_y1 + b2_y2 - b1_y1 - b1_y2) * 0.5
        sigma = paddle.pow((s_cw ** 2 + s_ch ** 2), 0.5)
        sin_alpha_1 = paddle.abs(s_cw) / sigma
        sin_alpha_2 = paddle.abs(s_ch) / sigma
        threshold = pow(2, 0.5) / 2
        sin_alpha = paddle.where(sin_alpha_1 > threshold, sin_alpha_2, sin_alpha_1)
        angle_cost = paddle.cos(paddle.asin(sin_alpha) * 2 - math.pi / 2)
        rho_x = (s_cw / cw) ** 2
        rho_y = (s_ch / ch) ** 2
        gamma = angle_cost - 2
        distance_cost = 2 - paddle.exp(gamma * rho_x) - paddle.exp(gamma * rho_y)
        omiga_w = paddle.abs(w1 - w2) / paddle.maximum(w1, w2)
        omiga_h = paddle.abs(h1 - h2) / paddle.maximum(h1, h2)
        shape_cost = paddle.pow(1 - paddle.exp(-1 * omiga_w), 4) + paddle.pow(1 - paddle.exp(-1 * omiga_h), 4)
        iou = iou - 0.5 * (distance_cost + shape_cost)
    loss = 1.0 - iou

    if self.reduction == 'sum':
        loss = loss.sum()
    elif self.reduction == 'mean':
        loss = loss.mean()

    return loss

您好,在IoUloss.py中添加SIouLoss,重新执行了一次python setup.py install。运行调用时,报CUDA(719)错误。麻烦大佬看看