Intersection over Union (IoU) for object detection

发布于 2024-06-21 00:55:38 字数 2111 浏览 33 评论 0

在目标检测中,我们需要定位出目标的位置,而我们的算法不可能百分百跟人工标注的数据完全匹配,因此需要一种衡量目标定位精度的标准。

IoU(Intersection over Union)是一种常见的用于衡量目标定位精度的标准,可以理解为重叠度,是一种简单的测量标准,只要是在输出中得出一个预测范围(bounding box) 的任务都可以用 IoU 来进行测量。

1

如上图所示,ground-truth 和 predicted 的存在误差,绿色框是人为标记的正确结果,红色框是算法预测出来的结果,IoU 要做的就是在这两个结果中测量算法的准确度,它定义了两个 bounding box 的重叠度 ,如下图所示:

2

$$IoU=\frac{A\bigcap B}{A\bigcup B}=\frac{A\bigcap B}{A+B-A\bigcap B}$$

就是矩形框 A、B 的重叠面积,占$A\bigcup B$的编辑的比例。

一般来说,IoU>0.5 就可以被认为一个不错的结果,IoU>0.7 结果就非常不错了,可以参见下图

3

Implementation

因为 IoU 的思想很简单,Python 实现可以参考[1]:

def bb_intersection_over_union(boxA, boxB):
# determine the (x, y)-coordinates of the intersection rectangle
xA = max(boxA[0], boxB[0])
yA = max(boxA[1], boxB[1])
xB = min(boxA[2], boxB[2])
yB = min(boxA[3], boxB[3])

# compute the area of intersection rectangle
interArea = (xB - xA + 1) * (yB - yA + 1)

# compute the area of both the prediction and ground-truth
# rectangles
boxAArea = (boxA[2] - boxA[0] + 1) * (boxA[3] - boxA[1] + 1)
boxBArea = (boxB[2] - boxB[0] + 1) * (boxB[3] - boxB[1] + 1)

# compute the intersection over union by taking the intersection
# area and dividing it by the sum of prediction + ground-truth
# areas - the interesection area
iou = interArea / float(boxAArea + boxBArea - interArea)

# return the intersection over union value
return iou

Reference

[1] Intersection over Union (IoU) for object detection

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

萤火眠眠

暂无简介

文章
评论
29 人气
更多

推荐作者

李珊平

文章 0 评论 0

Quxin

文章 0 评论 0

范无咎

文章 0 评论 0

github_ZOJ2N8YxBm

文章 0 评论 0

若言

文章 0 评论 0

南…巷孤猫

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文