深度学习知识点:IOU的计算及代码实现
if BBGT.size > 0:
# 计算IoU
# BBGT是真实坐标,bb是预测坐标
ixmin = np.maximum(BBGT[:, 0], bb[0])
iymin = np.maximum(BBGT[:, 1], bb[1])
ixmax = np.minimum(BBGT[:, 2], bb[2])
iymax = np.minimum(BBGT[:, 3], bb[3])
iw = np.maximum(ixmax - ixmin + 1., 0.)
ih = np.maximum(iymax - iymin + 1., 0.)
# interesting
inters = iw * ih
# union
# (bb[2] - bb[0]) 是预测框的width,(bb[3] - bb[1])是预测框的height
# (BBGT[:, 2] - BBGT[:, 0]) 是真实框的width
# (BBGT[:, 3] - BBGT[:, 1]) 是真实框的height
uni = ((bb[2] - bb[0] + 1.) * (bb[3] - bb[1] + 1.) +
(BBGT[:, 2] - BBGT[:, 0] + 1.) *
(BBGT[:, 3] - BBGT[:, 1] + 1.) - inters)
overlaps = inters / uni
# 检测到的目标框可能预若干个真实目标框都有交集,选择其中交集最大的
ovmax = np.max(overlaps)