关于SIoU的原理和代码实现(回顾IoU、GIoU、DIoU、CIoU)

论文:https://arxiv.org/pdf/2205.12740.pdf
代码实现(非官方):https://github.com/xialuxi/yolov5-car-plate/commit/aa41d1819b1fb03b4dc73e8a3e0000c46cfc370b
图片源自视频教程(这个大佬视频教程yyds):https://www.bilibili.com/video/BV1yi4y1g7ro?p=4

原理:

从最早的IoU到GIoU,再到DIoU和CIoU,现在出现了SIoU

L2损失与 IoU损失的比较请添加图片描述
GIoU损失

请添加图片描述
A代表蓝色的框,最大的矩形框。u代表GT和预测框的并集。

DIoU损失

在这里插入图片描述
图片一左侧的上面是GIoU,下面的是DIoU:其中黑色的代表anchor,蓝色的代表预测框,绿色的为GT框

在这里插入图片描述

CIoU损失

在这里插入图片描述
在这里插入图片描述

SIoU损失

再上面的基础上考虑了角度在这里插入图片描述
在论文中也重新定义了距离 cost和shape cost,
角度cost 定义如下:
在这里插入图片描述
这里我看的很奇怪的一点就是,这个α为啥带入到sin,又带入到反sin,这不是多此一举吗?σ就是两个框的中心距离呗。

距离cost 定义如下:
请添加图片描述
shape cost定义如下:
请添加图片描述
整的lost 定义:
请添加图片描述
还有很多细节没有分析、挖掘、探讨,这里只是草草的分享下,记录下。

代码实现:
        if SIoU:    # SIoU Loss https://arxiv.org/pdf/2205.12740.pdf
            sigma = torch.pow(cw ** 2 + ch ** 2, 0.5)
            sin_alpha_1 = ch / sigma
            sin_alpha_2 = cw / sigma
            threshold = pow(2, 0.5) / 2
            sin_alpha = torch.where(sin_alpha_1 > threshold, sin_alpha_2, sin_alpha_1)
            # angle_cost = 1 - 2 * torch.pow( torch.sin(torch.arcsin(sin_alpha) - np.pi/4), 2)
            angle_cost = torch.cos(torch.arcsin(sin_alpha) * 2 - np.pi / 2)
            rho_x = ((b2_x1 + b2_x2 - b1_x1 - b1_x2) / cw) ** 2
            rho_y = ((b2_y1 + b2_y2 - b1_y1 - b1_y2) / ch) ** 2
            gamma = 2 - angle_cost
            distance_cost = 2 - torch.exp(-1 * gamma * rho_x) - torch.exp(-1 * gamma * rho_y)
            omiga_w = torch.abs(w1 - w2) / torch.max(w1, w2)
            omiga_h = torch.abs(h1 - h2) / torch.max(h1, h2)
            shape_cost = torch.pow(1 - torch.exp(-1 * omiga_w), 4) + torch.pow(1 - torch.exp(-1 * omiga_h), 4)
            return iou - 0.5 * (distance_cost + shape_cost)

这个是美团yolov6实现的代码:
平均检测精度提升 0.3% AP

        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 = torch.pow(s_cw ** 2 + s_ch ** 2, 0.5)
            sin_alpha_1 = torch.abs(s_cw) / sigma
            sin_alpha_2 = torch.abs(s_ch) / sigma
            threshold = pow(2, 0.5) / 2
            sin_alpha = torch.where(sin_alpha_1 > threshold, sin_alpha_2, sin_alpha_1)
            angle_cost = torch.cos(torch.arcsin(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 - torch.exp(gamma * rho_x) - torch.exp(gamma * rho_y)
            omiga_w = torch.abs(w1 - w2) / torch.max(w1, w2)
            omiga_h = torch.abs(h1 - h2) / torch.max(h1, h2)
            shape_cost = torch.pow(1 - torch.exp(-1 * omiga_w), 4) + torch.pow(1 - torch.exp(-1 * omiga_h), 4)
            iou = iou - 0.5 * (distance_cost + shape_cost)
        loss = 1.0 - iou
  • 11
    点赞
  • 90
    收藏
    觉得还不错? 一键收藏
  • 16
    评论
Focal Giou是指在目标检测中使用的一种损失函数。引用\[2\]中提到,IoU Loss具有非负性、尺度不变性、同一性、对称性、三角不等性等特点,但是当两个图像没有相交时,无法比较两个图像的距离远近,无法体现两个图像到底是如何相交的。为了解决这个问题,引用\[3\]中提出了一种有效的IOU损失(EIOU),该损失函数使用额外的惩罚项来明确测量目标检测中的关键几何因素的差异,包括重叠区域、中心点和边长。而Focal Giou则是在Focal loss的基础上,结合了Giou损失函数,用于增强具有大IOU的高质量Anchor在目标检测模型优化过程中的贡献。 #### 引用[.reference_title] - *1* *2* [目标检测——map概念、Miou计算、IoU汇总IoUGIoUDIoUCIoUSIoU、EIoU、Wiou、Focal、alpha](https://blog.csdn.net/weixin_45464524/article/details/128649991)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [IOU破局之路 | Focal EIOU:打破IOU/GIOU/CIOU的局限](https://blog.csdn.net/CV_Autobot/article/details/127781131)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值