[英]Intersection over union understanding?
正在在线阅读一些代码以在 python 中实现 IOU,其中大部分部分我非常了解,但对于它的核心数学存在一些混淆。
这是代码:
def get_iou(boxA, boxB):
# This will calculate boxes given in any order...
# This will get max value between 2 boxes becuase max mening overlapping
# area just begins for x
interxA = max(boxA[0], boxB[0])
# This will get max value between 2 boxes becuase max mening overlapping
# area just begins for y
interyA = max(boxA[1], boxB[1])
# This will get min value between 2 boxes becuase min mening overlapping
# area just begins for x because bottom right should be less as it's ending
interxB = min(boxA[2], boxB[2])
# This will get min value between 2 boxes becuase min mening overlapping
# area just begins for y because bottom right should be less as it's ending
interyB = min(boxA[3], boxB[3])
# Now basic concept to find area of any rectangle in co-ordinate plane we
# can think in this way, this is values top-left: (xa, ya),
# bottom-right: (xb, yb)
# (xb - xa + 1) * (yb - ya + 1) this formula will yield us the area of that
# rectangle
# this will find area of intersection rectangle
interArea = max(0, interxB - interxA + 1) * max(0, interyB - interyA + 1)
boxAarea = (boxA[2] - boxA[0] + 1) * (boxA[3] - boxA[1] + 1)
boxBarea = (boxB[2] - boxB[0] + 1) * (boxB[3] - boxB[1] + 1)
return (interArea / (boxAarea + boxBarea - interArea))
在上面的代码中,为什么我们使用“+ 1”作为代码的一部分,因为我检查了有没有这样的代码:get_iou([25, 25, 175, 200], [45, 45, 175, 200])它改变了,但只有几个小数位? 如果我使用它是否重要,如果某些机构甚至可以解释我们为什么需要它,这将更有帮助。 提前致谢。
这可能是一个代码调整,以防止分数的分母在某些情况下为 0。 例如,如果我们从代码中删除+1
并且两个框相等,我们会得到返回 0/0。 在数学上这被解释为 1,但在计算上这将是一个数学错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.