我已经这样实现了 IOU:
import numpy as np
EPS = 1e-12
def get_iou( gt , pr , n_classes ):
class_wise = np.zeros(n_classes)
for cl in range(n_classes):
intersection = np.sum(( gt == cl )*( pr == cl ))
union = np.sum(np.maximum( ( gt == cl ) , ( pr == cl ) ))
iou = float(intersection)/( union + EPS )
class_wise[ cl ] = iou
return class_wise
并像这样使用它:
for l,y in zip(gt_label_list,network_prediction):
gt=cv2.imread(l,0)
pr=y
iou.append(get_iou(gt,pr,num_classes=20))
ious = np.array(iou)
print("Class wise IoU near" , np.mean(ious , axis=0 ))
print("Total IoU near" , np.mean(ious ))
但即使我提供gt和pr相同的图像(cityscapes 500 验证图像集),Total IOU 也不合理:
Class wise IoU near [0.968 0.932 0.982 0.404 0.378 0.982 0.582 0.946 0.972 0.482 0.886 0.804 0.506 0.958 0.16 0.15 0.044 0.186 0.69 1. ]
Total IoU near 0.6505999999999998
我知道某些类没有出现在某些图像中,但是文章如何报告 MioU 超过 70%?