MIoU,Mean IoU,Mean Intersection over Union,均交并比

2021-12-06 21:32:12 浏览数 (2)

  • MIoU(Mean IoU,Mean Intersection over Union,均交并比,交集 / 并集),也就是语义分割中所谓的 Mask IoU 。
  • MIoU:计算两圆交集(橙色TP)与两圆并集(红色FN 橙色TP 黄色FP)之间的比例,理想情况下两圆重合,比例为1。
代码语言:javascript复制
 from sklearn.metrics import confusion_matrix  
 import numpy as np

 def compute_iou(y_pred, y_true):
     # ytrue, ypred is a flatten vector
     y_pred = y_pred.flatten()
     y_true = y_true.flatten()
     current = confusion_matrix(y_true, y_pred, labels=[0, 1])
     # compute mean iou
     intersection = np.diag(current)
     ground_truth_set = current.sum(axis=1)
     predicted_set = current.sum(axis=0)
     union = ground_truth_set   predicted_set - intersection
     IoU = intersection / union.astype(np.float32)
     return np.mean(IoU)

0 人点赞