iou函数有一点bug
""" iou函数未检测当两个框没有intersection的时候,如 box1 = (1,2,3,4) box2 = (5,6,7,8) """ def iou(box1, box2): xi1 = np.maximum(box1_x1, box2_x1) yi1 = np.maximum(box1_y1, box2_y1) xi2 = np.minimum(box1_x2, box2_x2) yi2 = np.minimum(box1_y2, box2_y2) inter_width = xi1-xi2 inter_height =yi1-yi2 inter_area = inter_width * inter_height #suggest add the code below if inter_width>0 and inter_height>0: inter_area = 0
box1_area = (box1_x1 - box1_x2)*(box1_y1-box1_y2)
box2_area = (box2_x1 - box2_x2)*(box2_y1-box2_y2)
union_area = box1_area + box2_area - inter_area
# compute the IoU
iou = inter_area/ union_area
""" iou函数未检测当两个框没有intersection的时候,如 box1 = (1,2,3,4) box2 = (5,6,7,8) """ def iou(box1, box2): xi1 = np.maximum(box1_x1, box2_x1) yi1 = np.maximum(box1_y1, box2_y1) xi2 = np.minimum(box1_x2, box2_x2) yi2 = np.minimum(box1_y2, box2_y2) inter_width = xi1-xi2 inter_height =yi1-yi2 inter_area = inter_width * inter_height #suggest add the code below if inter_width>0 and inter_height>0: inter_area = 0
box1_area = (box1_x1 - box1_x2)*(box1_y1-box1_y2) box2_area = (box2_x1 - box2_x2)*(box2_y1-box2_y2) union_area = box1_area + box2_area - inter_area # compute the IoU iou = inter_area/ union_area
在吴恩达深度学习car detection的代码iou函数中