位置: IT常识 - 正文

YOLOv5|YOLOv7|YOLOv8改各种IoU损失函数:YOLOv8涨点Trick,改进添加SIoU损失函数、EIoU损失函数、GIoU损失函数、α-IoU损失函数

编辑:rootadmin
YOLOv5|YOLOv7|YOLOv8改各种IoU损失函数:YOLOv8涨点Trick,改进添加SIoU损失函数、EIoU损失函数、GIoU损失函数、α-IoU损失函数

推荐整理分享YOLOv5|YOLOv7|YOLOv8改各种IoU损失函数:YOLOv8涨点Trick,改进添加SIoU损失函数、EIoU损失函数、GIoU损失函数、α-IoU损失函数,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

💡该教程为改进入门指南,属于《芒果书》📚系列,包含大量的原创首发改进方式, 所有文章都是全网首发原创改进内容🚀

💡本篇文章 基于 YOLOv5、YOLOv7芒果改进YOLO系列:YOLOv7改进IoU损失函数:YOLOv7涨点Trick,改进添加SIoU损失函数、EIoU损失函数、GIoU损失函数、α-IoU损失函数、打造全新YOLOv7检测器。

重点:🔥🔥🔥有不少同学已经反应有效涨点!!! 🌟其他改进内容:CSDN原创YOLO进阶目录 | 《芒果改进YOLO进阶指南》推荐!

最全《芒果书📚》改进目录:YOLOv5改进、YOLOv7改进(芒果书系列)目录一览|原创YOLO改进模型全系列目录 | 人工智能专家老师联袂推荐

文章目录解析|YOLOv7网络模型源代码训练推理教程解析总结|YOLO系列期刊创新点总结核心代码改进改进核心代码改进α-IoU核心代码SIoU改进EIoU改进GIoU改进α-IoU改进代码直接运行解析|YOLOv7网络模型源代码训练推理教程解析手把手调参最新 YOLOv7 模型 推理部分(一)🌟手把手调参最新 YOLOv7 模型 训练部分(二)🌟总结|YOLO系列期刊创新点总结

💡🎈☁️:国庆假期浏览了几十篇YOLO改进英文期刊,总结改进创新的一些相同点(期刊创新点持续更新)

💡🎈☁️:国庆假期看了一系列图像分割Unet、DeepLabv3+改进期刊论文,总结了一些改进创新的技巧

核心代码改进YOLOv5|YOLOv7|YOLOv8改各种IoU损失函数:YOLOv8涨点Trick,改进添加SIoU损失函数、EIoU损失函数、GIoU损失函数、α-IoU损失函数

以下SIoU、EIoU、GIoU、α-IoU改进,代码均在博主开源的YOLOAir中有写

改进核心代码

在YOLOv5中,使用以下函数替换原有的utils/metrics.py文件中的bbox_iou函数

如果在YOLOv7中,使用以下函数替换原有的utils/general.py文件中的bbox_iou函数

def bbox_iou(box1, box2, x1y1x2y2=True, GIoU=False, DIoU=False, CIoU=False, EIoU=False, SIoU=False, eps=1e-7): # Returns the IoU of box1 to box2. box1 is 4, box2 is nx4 box2 = box2.T # Get the coordinates of bounding boxes if x1y1x2y2: # x1, y1, x2, y2 = box1 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] else: # transform from xywh to xyxy 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 = (torch.min(b1_x2, b2_x2) - torch.max(b1_x1, b2_x1)).clamp(0) * \ (torch.min(b1_y2, b2_y2) - torch.max(b1_y1, b2_y1)).clamp(0) # Union Area w1, h1 = b1_x2 - b1_x1, b1_y2 - b1_y1 + eps w2, h2 = b2_x2 - b2_x1, b2_y2 - b2_y1 + eps union = w1 * h1 + w2 * h2 - inter + eps iou = inter / union if CIoU or DIoU or GIoU or EIoU or SIoU: cw = torch.max(b1_x2, b2_x2) - torch.min(b1_x1, b2_x1) # convex (smallest enclosing box) width ch = torch.max(b1_y2, b2_y2) - torch.min(b1_y1, b2_y1) # convex height if CIoU or DIoU or EIoU or SIoU: # Distance or Complete IoU https://arxiv.org/abs/1911.08287v1 c2 = cw ** 2 + ch ** 2 + 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 DIoU: #DIoU return iou - rho2 / c2 # DIoU elif CIoU: #CIoU https://github.com/Zzh-tju/DIoU-SSD-pytorch/blob/master/utils/box/box_utils.py#L47 v = (4 / math.pi ** 2) * torch.pow(torch.atan(w2 / h2) - torch.atan(w1 / h1), 2) with torch.no_grad(): alpha = v / (v - iou + (1 + eps)) return iou - (rho2 / c2 + v * alpha) # CIoU elif SIoU:# SIoU 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) return iou - 0.5 * (distance_cost + shape_cost) else:# EIoU w_dis=torch.pow(b1_x2-b1_x1-b2_x2+b2_x1, 2) h_dis=torch.pow(b1_y2-b1_y1-b2_y2+b2_y1, 2) cw2=torch.pow(cw , 2)+eps ch2=torch.pow(ch , 2)+eps return iou-(rho2/c2+w_dis/cw2+h_dis/ch2) else: c_area = cw * ch + eps # convex area return iou - (c_area - union) / c_area # GIoU https://arxiv.org/pdf/1902.09630.pdf return iou # IoU改进α-IoU核心代码def bbox_alpha_iou(box1, box2, x1y1x2y2=False, GIoU=False, DIoU=False, CIoU=False, alpha=2, eps=1e-9): # Returns tsqrt_he IoU of box1 to box2. box1 is 4, box2 is nx4 box2 = box2.T # Get the coordinates of bounding boxes if x1y1x2y2: # x1, y1, x2, y2 = box1 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] else: # transform from xywh to xyxy 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 = (torch.min(b1_x2, b2_x2) - torch.max(b1_x1, b2_x1)).clamp(0) * \ (torch.min(b1_y2, b2_y2) - torch.max(b1_y1, b2_y1)).clamp(0) # Union Area w1, h1 = b1_x2 - b1_x1, b1_y2 - b1_y1 + eps w2, h2 = b2_x2 - b2_x1, b2_y2 - b2_y1 + eps union = w1 * h1 + w2 * h2 - inter + eps # change iou into pow(iou+eps) # iou = inter / union iou = torch.pow(inter/union + eps, alpha) # beta = 2 * alpha if GIoU or DIoU or CIoU: cw = torch.max(b1_x2, b2_x2) - torch.min(b1_x1, b2_x1) # convex (smallest enclosing box) width ch = torch.max(b1_y2, b2_y2) - torch.min(b1_y1, b2_y1) # convex height if CIoU or DIoU: # Distance or Complete IoU https://arxiv.org/abs/1911.08287v1 c2 = (cw ** 2 + ch ** 2) ** alpha + eps # convex diagonal rho_x = torch.abs(b2_x1 + b2_x2 - b1_x1 - b1_x2) rho_y = torch.abs(b2_y1 + b2_y2 - b1_y1 - b1_y2) rho2 = ((rho_x ** 2 + rho_y ** 2) / 4) ** alpha # center distance if DIoU: return iou - rho2 / c2 # DIoU elif CIoU: # https://github.com/Zzh-tju/DIoU-SSD-pytorch/blob/master/utils/box/box_utils.py#L47 v = (4 / math.pi ** 2) * torch.pow(torch.atan(w2 / h2) - torch.atan(w1 / h1), 2) with torch.no_grad(): alpha_ciou = v / ((1 + eps) - inter / union + v) # return iou - (rho2 / c2 + v * alpha_ciou) # CIoU return iou - (rho2 / c2 + torch.pow(v * alpha_ciou + eps, alpha)) # CIoU else: # GIoU https://arxiv.org/pdf/1902.09630.pdf # c_area = cw * ch + eps # convex area # return iou - (c_area - union) / c_area # GIoU c_area = torch.max(cw * ch + eps, union) # convex area return iou - torch.pow((c_area - union) / c_area + eps, alpha) # GIoU else: return iou # torch.log(iou+eps) or iouSIoU改进

参考上面的核心代码

将iou = bbox_iou(pbox.T, tbox[i], x1y1x2y2=False, CIoU=True)替换为iou = bbox_iou(pbox.T, tbox[i], x1y1x2y2=False, SIoU=True)EIoU改进

参考上面的核心代码

将iou = bbox_iou(pbox.T, tbox[i], x1y1x2y2=False, CIoU=True)替换为iou = bbox_iou(pbox.T, tbox[i], x1y1x2y2=False, EIoU=True)GIoU改进

参考上面的核心代码

将iou = bbox_iou(pbox.T, tbox[i], x1y1x2y2=False, CIoU=True)替换为iou = bbox_iou(pbox.T, tbox[i], x1y1x2y2=False, GIoU=True)α-IoU改进

参考上面的核心代码

bbox_alpha_iou将iou = bbox_iou(pbox.T, tbox[i], x1y1x2y2=False, CIoU=True)替换为iou = bbox_alpha_iou(pbox.T, tbox[i], x1y1x2y2=False, CIoU=True)

以上是yolov5的改进

yolov7 将 tbox[i] 改为 selected_tbox

比如 iou = bbox_iou(pbox.T, tbox[i], x1y1x2y2=False, CIoU=True) 改为iou = bbox_iou(pbox.T, selected_tbox, x1y1x2y2=False, CIoU=True)

代码直接运行python train.py cfg yolov7.yaml即可
本文链接地址:https://www.jiuchutong.com/zhishi/300622.html 转载请保留说明!

上一篇:【一起学Rust | 框架篇 | Viz框架】轻量级 Web 框架——Viz(rust 入门教程)

下一篇:Python实现朴素贝叶斯分类器(用python编写素数)

  • 应交所得税的计算公式
  • 房地产企业样板间装修费计入什么科目
  • 投资入股变更股权比例
  • 项目奖金个人所得税怎么算
  • 房地产行业企业所得税政策
  • 盘亏的设备按正常报废处理是否符合会计制度要求
  • 印花税是当月交当月的吗
  • 土地增值税清算利息扣除规定
  • 台湾企业不能在大陆或香港上市吗
  • 可转换公司债券属于哪一类金融资产
  • 用银行存款支付罚款
  • 固定资产减少会怎么样
  • 一次性离职补偿金如何避税
  • 跨区域施工要交什么税
  • 作废发票 红字发票
  • 采用差额计税开什么发票
  • 一般纳税人有哪些费用
  • 自产农产品销售怎么做账
  • 代收污水处理费要交税吗
  • 注册资金印花税怎么算
  • win10桌面2怎么使用
  • PHP:oci_password_change()的用法_Oracle函数
  • 安防监控利润怎么样
  • 发票未到先付款的账务处理
  • 利息收入结转的正确分录
  • fxssvc.exe
  • 固定资产转出是什么意思
  • 为高新技术企业授牌
  • ghoststarttrayapp.exe是什么进程 有什么作用 ghoststarttrayapp进程查询
  • 若依官网
  • 最贵的苹果4
  • 转出固定资产账务处理
  • 增值税的具体内容包括
  • 车辆运输费计入什么科目
  • 金融企业会计计提贷款呆账准备金主要贯彻了
  • 员工出差过程中猝死赔偿
  • 资产处置损益计算公式
  • elementui的upload组件详解
  • php数组处理函数array_push会影响源数组的元素吗
  • 进项税额销项税额
  • golang 调用动态库
  • 服务类收入确认
  • 免收印花税
  • 酒店业营业税税率
  • 资产负债表净资产为负数
  • js回调函数如何返回值
  • 发放年终奖的会议纪要
  • phpcms是什么
  • 深圳税务2021
  • 个人所得税率怎么退
  • 库存商品是表达什么意思
  • 盘盈盘亏怎么填写
  • 贸易公司开发票进项跟销项不符合怎么办?
  • 工程项目劳务分包招投标要多久
  • 收到返利怎么做会计分录
  • 差旅费借记什么科目
  • 未取得增值税发票措施有哪些
  • Windows Server 2008禁止模块安装提升网络性能
  • solaris init
  • repair.exe是什么软件
  • centos 搜索
  • 操作系统的定义
  • win8取消开始界面
  • rhel6提供5种基本的安装方式
  • 使用jquery操作dom
  • nodejs执行cmd命令
  • node.js配置
  • net命令大全
  • js 在线调试
  • 安卓工程如何正常启动
  • JavaScript中的NaN代表什么
  • js中unbind
  • javascript中this的用法
  • 用js实现类的方法
  • 专项附加扣除当月填报何时生效
  • 河南十大纳税公司
  • 个人所得税怎么退税
  • shell ftp -n
  • 继承房产过户后可以要求分割吗?
  • 湖北航天金税盘服务器地址
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设