前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >深度学习中IU、IoU(Intersection over Union)的概念理解以及python程序实现

深度学习中IU、IoU(Intersection over Union)的概念理解以及python程序实现

作者头像
老潘
修改2018-06-22 15:05:51
5.2K0
修改2018-06-22 15:05:51
举报

IoU(Intersection over Union)

Intersection over Union是一种测量在特定数据集中检测相应物体准确度的一个标准。我们可以在很多物体检测挑战中,例如PASCAL VOC challenge中看多很多使用该标准的做法。

通常我们在 HOG + Linear SVM object detectors 和 Convolutional Neural Network detectors (R-CNN, Faster R-CNN, YOLO, etc.)中使用该方法检测其性能。注意,这个测量方法和你在任务中使用的物体检测算法没有关系。

IoU是一个简单的测量标准,只要是在输出中得出一个预测范围(bounding boxex)的任务都可以用IoU来进行测量。为了可以使IoU用于测量任意大小形状的物体检测,我们需要: 1、 ground-truth bounding boxes(人为在训练集图像中标出要检测物体的大概范围); 2、我们的算法得出的结果范围。

也就是说,这个标准用于测量真实和预测之间的相关度,相关度越高,该值越高。

如下图:

《深度学习中IU、IoU(Intersection over Union)的概念理解以及python程序实现》
《深度学习中IU、IoU(Intersection over Union)的概念理解以及python程序实现》

下图展示了ground-truth和predicted的结果,绿色标线是人为标记的正确结果,红色标线是算法预测出来的结果,IoU要做的就是在这两个结果中测量算法的准确度。

《深度学习中IU、IoU(Intersection over Union)的概念理解以及python程序实现》
《深度学习中IU、IoU(Intersection over Union)的概念理解以及python程序实现》

如上图,很简单,IoU相当于两个区域重叠的部分除以两个区域的集合部分得出的结果。 一般来说,这个score > 0.5 就可以被认为一个不错的结果了。

《深度学习中IU、IoU(Intersection over Union)的概念理解以及python程序实现》
《深度学习中IU、IoU(Intersection over Union)的概念理解以及python程序实现》

python程序实现

具体实现过程请移步:https://www.pyimagesearch.com/2016/11/07/intersection-over-union-iou-for-object-detection/

代码语言:javascript
复制
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

后记

IoU在FCN中称为IU,初看Fully Convolutional Networks for Semantic Segmentation论文,其中的IU概念没有能理解,其实那里的IU也就是IoU,检测物体轮廓不一定非得是方框,也可以是沿着物体的边线:

《深度学习中IU、IoU(Intersection over Union)的概念理解以及python程序实现》
《深度学习中IU、IoU(Intersection over Union)的概念理解以及python程序实现》

在实际的任务中,根据不同的任务要求来写不同具体实现的检测方法,但说白了其实都是IoU或者IU。 另外mean IU指的是不同类别识别准确度的平均值,比如一幅图中要识别三个物体,mean IU就是三个物体分别准确度加起来的平均值。

参考资料:

1、https://www.pyimagesearch.com/2016/11/07/intersection-over-union-iou-for-object-detection/ 2、https://stackoverflow.com/questions/25349178/calculating-percentage-of-bounding-box-overlap-for-image-detector-evaluation/42874377#42874377 3、https://stackoverflow.com/questions/25349178/calculating-percentage-of-bounding-box-overlap-for-image-detector-evaluation/42874377#42874377

此文由腾讯云爬虫爬取,文章来源于Oldpan博客

欢迎关注Oldpan博客公众号,持续酝酿深度学习质量文:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017年12月14日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • IoU(Intersection over Union)
  • python程序实现
  • 后记
    • 参考资料:
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档