# -*- coding: utf-8 -*-
# @Time    : 2022/8/7 10:34
# @Author  : hllyzms
import mathdef euclidean_distance(p1, p2):'''计算两个点的欧式距离'''x1, y1 = p1x2, y2 = p2return math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)class BBox(object):def __init__(self, x, y, r, b):self.x, self.y, self.r, self.b = x, y, r, bdef __xor__(self, other):"""计算box和other的IoU"""cross = self & otherunion = self | otherreturn cross / (union + 1e-6)def __or__(self, other):""" 计算box和other的并集"""cross = self & otherreturn self.area + other.area - crossdef __and__(self, other):"""计算box和other的交集"""xmax = min(self.r, other.r)ymax = min(self.b, other.b)xmin = max(self.x, other.x)ymin = max(self.y, other.y)return BBox(xmin, ymin, xmax, ymax).areadef boundof(self, other):"""计算box和other的边缘外包框,使得2个box都在框内的最小矩形"""xmin = min(self.x, other.x)ymin = min(self.y, other.y)xmax = max(self.r, other.r)ymax = max(self.b, other.b)return BBox(xmin, ymin, xmax, ymax)def center_distance(self, other):'''计算两个box的中心点距离'''return euclidean_distance(self.center, other.center)def bound_diagonal_distance(self, other):'''计算两个box的bound的对角线距离'''bound = self.boundof(other)return euclidean_distance((bound.x, bound.y), (bound.r, bound.b))@propertydef center(self):return (self.x + self.r) / 2, (self.y + self.b) / 2@propertydef area(self):return self.width * self.height@propertydef width(self):# todo 如果不考虑右侧的一个像素 返回 self.r - self.xreturn self.r - self.x + 1@propertydef height(self):# todo 如果不考虑下侧的一个像素 返回 self.b - self.yreturn self.b - self.y + 1def __repr__(self):return f"{self.x}, {self.y}, {self.r}, {self.b}"def IoU(box1: BBox, box2: BBox):return box1 ^ box2def GIoU(box1: BBox, box2: BBox):bound_area = box1.boundof(box2).areaunion_area = box1 | box2return IoU(box1, box2) - (bound_area - union_area) / bound_areadef DIoU(box1: BBox, box2: BBox):d = box1.center_distance(box2)c = box1.bound_diagonal_distance(box2)return IoU(box1, box2) - d ** 2 / c ** 2def CIoU(box1: BBox, box2: BBox):diou = DIoU(box1, box2)v = 4 / (math.pi ** 2) * (math.atan(box1.width / box1.height) - math.atan(box2.width / box2.height)) ** 2iou = IoU(box1, box2)alpha = v / (1 - iou + v)return diou - alpha * vbox1 = BBox(*[10, 10, 100, 200])
box2 = BBox(*[50, 50, 150, 180])# box1 = BBox(*[1, 1, 3, 3])
# box2 = BBox(*[3, 3, 5, 5])print(IoU(box1, box2))
print(GIoU(box1, box2))
print(DIoU(box1, box2))
print(CIoU(box1, box2))

IOU GIOU DIOU CIOU相关推荐

  1. IoU GIoU DIoU CIoU分析比较

    IoU GIoU DIoU CIoU分析比较 IoU 1. IoU的简介及原理解析 2.IOU的应用有哪些? GIoU 1.Iou的缺陷 2.GIoU的简介及原理解析 3.GIoU的性质 DIoU & ...

  2. IOU .GIOU.DIOU.CIOU

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 IOU .GIOU.DIOU.CIOU 一.IOU(Intersection over Union) 二.GIOU(Generaliz ...

  3. IoU系列(IoU, GIoU, DIoU, CIoU)

    ​​​​​ 写在前面 一.IoU (Intersection over Union) 1.1 IoU的优点 1.2 作为损失函数会出现的问题(缺点) 二.GIoU (Generalized) 三. D ...

  4. IOU GIOU DIOU CIOU 及代码实现

    总体发展过程: IOU IOU(交并比)顾名思义就是两个框的交集除以他们的并集. IOU Loss:IOU Loss = 1 -IOU(比较常用) IOU 的优点:1.能够很好的反应重合的程度    ...

  5. 基于IOU的损失函数合集, IoU, GIoU, DIoU,CIoU, EIoU

      目标检测任务的损失函数一般由 Classificition Loss(分类损失函数)和Bounding Box Regeression Loss(回归损失函数)两部分构成.   Bounding ...

  6. 目标检测回归损失函数简介:SmoothL1/IoU/GIoU/DIoU/CIoU Loss

    点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 来源:极市平台 目标检测任务的损失函数由Classificitio ...

  7. 目标检测回归损失函数:SmoothL1/IoU/GIoU/DIoU/CIoU Loss

    文章目录 1. Smooth L1 Loss 1.1 假设x为预测框和真实框之间的数值差异,常用的L1和L2 Loss定义为: 1.2 上述的3个损失函数对x的导数分别为: 1.3 实际目标检测框回归 ...

  8. IOU, GIOU, DIOU, CIOU

    IOU IOU是用来衡量两个边界框的重叠程度的.普通的IOU也分为两种,一种是交并比,一种是最小面积与并集的比 计算公式如下: 并集面积 = 面积A + 面积B - 交集面积 交集面积 = 框A与框B ...

  9. 【IoU全总结】GIoU, DIoU, CIoU, EIoUFocal, αIoU, SIoU,WIoU【基础收藏】

最新文章

  1. 个人比较喜欢的JS网页跳转传值
  2. 爱之箭发射(las)
  3. EditText 自动保留两位小数
  4. 学习 WCF (4)--学会使用配置文件
  5. [BUUCTF-pwn]——wdb_2018_2nd_easyfmt
  6. 鲁迅文学院60周年庆
  7. 警钟 | 还不会Spring Boot集成JWT,你可能错过了大厂的Office了
  8. 20145212 罗天晨 Web安全基础实践
  9. 《代码整洁之道姐妹篇》
  10. Centos7 搭建 Socks 服务
  11. php laypage,ThinkPHP5、内容管理系统、前端框架layui、layPage模块
  12. 零基础新手如何自学PS
  13. WPF:ListView 分页
  14. JS 把数组按倒序排列
  15. Linux中的bin文件夹
  16. syswow64删除文件_syswow64 c盘syswow64可以删除吗
  17. HDU1859 最小长方形 (水
  18. 【已解决】VS code源代码控制器显示5k+的修改文件
  19. 跨专业保研浙大计算机,保研经验:排名第一,论文两篇,七项专利,两个国家级大创,夏令营斩获多个offer,成功上岸985!...
  20. 复旦博士写了130行代码搞定核酸统计

热门文章

  1. 计算机本科应届生年薪30W40W真的很普遍吗?
  2. layui 日期重置_layui前段框架日期控件使用方法详解
  3. 软件工程双人项目总结——夏睿张静
  4. 3D打印机打印星战尤达大师模型细节惊人
  5. python网易云单首音乐下载
  6. 决策树算法,妈妈再也不用担心我不想学机器学习了
  7. 树莓派2b/3b配置WLAN网络
  8. alpha hull
  9. 软件的黑盒白盒测试,软件测试黑盒白盒测试用例
  10. Device Tree语法(上)