目标检测之IoU(intersecton over union)标准

https://www.pyimagesearch.com/2016/11/07/intersection-over-union-iou-for-object-detection/

目标检测之IoU(intersecton over union)标准

绿色代表ground truth box,红色代表predictive box. 

ground truth box 需要手动标注,predictive box是你选用的模型计算出来的结果。

将两者放在一起用IOU来衡量我们的模型检测目标的有效性。

从下图你可以很直观的看到IoU的计算。


目标检测之IoU(intersecton over union)标准


目标检测之IoU(intersecton over union)标准

从python编程的角度实现

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(intersecton over union)标准

目标检测之IoU(intersecton over union)标准

目标检测之IoU(intersecton over union)标准



目标检测之IoU(intersecton over union)标准

目标检测之IoU(intersecton over union)标准






目标检测之IoU(intersecton over union)标准

以上这正图片来自IJCV论文“weakly supervised localization and learning with generic knowledge”

图中黄色代表groundtruthbox,红色代表false positive 示例,绿色框代表 true positive,最右端的是未检测到的object,是FN的示例。

图中的Corloc=TP/(TP+FP)=2/3=66%.它与IOU存在的差别在于一个是正确的示例个数之比以及一个是面积之比。