IOU GIOU DIOU CIOU
# -*- 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相关推荐
- IoU GIoU DIoU CIoU分析比较
IoU GIoU DIoU CIoU分析比较 IoU 1. IoU的简介及原理解析 2.IOU的应用有哪些? GIoU 1.Iou的缺陷 2.GIoU的简介及原理解析 3.GIoU的性质 DIoU & ...
- IOU .GIOU.DIOU.CIOU
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 IOU .GIOU.DIOU.CIOU 一.IOU(Intersection over Union) 二.GIOU(Generaliz ...
- IoU系列(IoU, GIoU, DIoU, CIoU)
写在前面 一.IoU (Intersection over Union) 1.1 IoU的优点 1.2 作为损失函数会出现的问题(缺点) 二.GIoU (Generalized) 三. D ...
- IOU GIOU DIOU CIOU 及代码实现
总体发展过程: IOU IOU(交并比)顾名思义就是两个框的交集除以他们的并集. IOU Loss:IOU Loss = 1 -IOU(比较常用) IOU 的优点:1.能够很好的反应重合的程度 ...
- 基于IOU的损失函数合集, IoU, GIoU, DIoU,CIoU, EIoU
目标检测任务的损失函数一般由 Classificition Loss(分类损失函数)和Bounding Box Regeression Loss(回归损失函数)两部分构成. Bounding ...
- 目标检测回归损失函数简介:SmoothL1/IoU/GIoU/DIoU/CIoU Loss
点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 来源:极市平台 目标检测任务的损失函数由Classificitio ...
- 目标检测回归损失函数:SmoothL1/IoU/GIoU/DIoU/CIoU Loss
文章目录 1. Smooth L1 Loss 1.1 假设x为预测框和真实框之间的数值差异,常用的L1和L2 Loss定义为: 1.2 上述的3个损失函数对x的导数分别为: 1.3 实际目标检测框回归 ...
- IOU, GIOU, DIOU, CIOU
IOU IOU是用来衡量两个边界框的重叠程度的.普通的IOU也分为两种,一种是交并比,一种是最小面积与并集的比 计算公式如下: 并集面积 = 面积A + 面积B - 交集面积 交集面积 = 框A与框B ...
- 【IoU全总结】GIoU, DIoU, CIoU, EIoUFocal, αIoU, SIoU,WIoU【基础收藏】
最新文章
- 个人比较喜欢的JS网页跳转传值
- 爱之箭发射(las)
- EditText 自动保留两位小数
- 学习 WCF (4)--学会使用配置文件
- [BUUCTF-pwn]——wdb_2018_2nd_easyfmt
- 鲁迅文学院60周年庆
- 警钟 | 还不会Spring Boot集成JWT,你可能错过了大厂的Office了
- 20145212 罗天晨 Web安全基础实践
- 《代码整洁之道姐妹篇》
- Centos7 搭建 Socks 服务
- php laypage,ThinkPHP5、内容管理系统、前端框架layui、layPage模块
- 零基础新手如何自学PS
- WPF:ListView 分页
- JS 把数组按倒序排列
- Linux中的bin文件夹
- syswow64删除文件_syswow64 c盘syswow64可以删除吗
- HDU1859 最小长方形 (水
- 【已解决】VS code源代码控制器显示5k+的修改文件
- 跨专业保研浙大计算机,保研经验:排名第一,论文两篇,七项专利,两个国家级大创,夏令营斩获多个offer,成功上岸985!...
- 复旦博士写了130行代码搞定核酸统计