计算边界框预测的IOU

计算边界框预测的IOU

本文介绍了计算边界框预测的IOU的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有图片中给出的这两个边界框.框坐标如下:

I have these two bounding boxes as given in the image. the box cordinates are given as below :

框 1 = [0.23072851 0.44545859 0.56389928 0.67707491]框 2 = [0.22677664 0.38237819 0.85152483 0.75449795]

box 1 = [0.23072851 0.44545859 0.56389928 0.67707491]box 2 = [0.22677664 0.38237819 0.85152483 0.75449795]

坐标是这样的:ymin, xmin, ymax, xmax

The coordinate are like this : ymin, xmin, ymax, xmax

我计算IOU如下:

def get_iou(box1, box2):
"""Implement the intersection over union (IoU) between box1 and box2
    
    Arguments:
    box1 -- first box, numpy array with coordinates (ymin, xmin, ymax, xmax)
    box2 -- second box, numpy array with coordinates (ymin, xmin, ymax, xmax)
    """
# ymin, xmin, ymax, xmax = box

y11, x11, y21, x21 = box1
y12, x12, y22, x22 = box2

yi1 = max(y11, y12)
xi1 = max(x11, x12)
yi2 = min(y21, y22)
xi2 = min(x21, x22)
inter_area = max(((xi2 - xi1) * (yi2 - yi1)), 0)
# Calculate the Union area by using Formula: Union(A,B) = A + B - Inter(A,B)
box1_area = (x21 - x11) * (y21 - y11)
box2_area = (x22 - x12) * (y22 - y12)
union_area = box1_area + box2_area - inter_area
# compute the IoU
iou = inter_area / union_area
return iou

根据我的理解,这两个盒子完全重叠,所以 IOU 应该是 1.但是我得到的 IOU 0.33193138665968164.是不是我做错了什么,或者我以不正确的方式解释了它.任何这方面的建议都会有所帮助.

Based on my understanding these 2 boxes completely overlap each other so IOU should be 1. However I get an IOU of 0.33193138665968164. Is there something which I am doing wrong or I am interpreting it in an incorrect way. Any suggestions in this regard would be helpful.

推荐答案

您以错误的方式解释了 IoU.

You are interpreting the IoU in an incorrect way.

如果注意您的示例,您会注意到两个边界框区域的并集比区域的交集大得多.因此,IoU(实际上是交集/并集)比 1 小得多是有道理的.

If pay attention to your example, you notice that the union of the areas of the two bounding boxes is much bigger than the intersection of the areas. So it makes sense that the IoU - which is indeed intersection / union - is much smaller than one.

当你说

根据我的理解,这两个盒子完全重叠,所以 IOU 应该是 1.

事实并非如此.在您的情况下,两个边界框仅在一个完全包含在另一个中的意义上重叠.但是如果这种情况没有受到惩罚,IoU 总是可以最大化预测与图像一样大的边界框 - 这显然没有意义.

that is not true. In your situation the two bounding boxes overlap only in the sense that one is completely contained in the other. But if this situation weren't penalized, IoU could be always maximized predicting a bounding box as big as the image - which clearly doesn't make sense.

这篇关于计算边界框预测的IOU的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 16:36