1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| if __name__ == '__main__': pred_boxes = np.array([[30, 280, 200, 300], [20, 300, 100, 360]]) target_boxes = np.array([[10, 10, 50, 50], [40, 270, 100, 380], [450, 300, 500, 500]])
# ious大小为[N2, N1] # N1表示pred_boxes的个数 # N2表示target_boxes的个数 ious = iou_of(torch.from_numpy(pred_boxes), torch.from_numpy(target_boxes))
print('ious: ', ious)
img = np.ones((650, 650, 3)) * 255 for item in target_boxes: xmin, ymin, xmax, ymax = item cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 255, 0), thickness=2) for item in pred_boxes: xmin, ymin, xmax, ymax = item cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 0, 255), thickness=1)
cv2.imshow('img', img) cv2.waitKey(0)
cv2.imwrite('iou.png', img) ###################### 输出每个GT和预测边界框的IoU ious: tensor([[0.0000, 0.0000], [0.1364, 0.4615], [0.0000, 0.0000]])
|