我为每个图像(汽车/人/人行道)设置了多个类的numpy数组,如何有效地计算每个类的IOU和所有类的平均IOU?
答案 0 :(得分:0)
1.要计算所有类的平均IoU,请使用tensorflow中的tf.metrics.mean_iou函数。
https://www.tensorflow.org/api_docs/python/tf/metrics/mean_iou
2.为计算单个类的IOU,构造一个混淆矩阵并使用矩阵进行每类IOU计算。
def confusion_matrix(eval_segm, gt_segm, **kwargs):
merged_maps = np.bitwise_or(np.left_shift(gt_segm.astype('uint16'), 8), eval_segm.astype('uint16'))
hist = np.bincount(np.ravel(merged_maps))
nonzero = np.nonzero(hist)[0]
pred, label = np.bitwise_and(255, nonzero), np.right_shift(nonzero, 8)
class_count = np.array([pred, label]).max() + 1
conf_matrix = np.zeros([class_count, class_count], dtype='uint64')
conf_matrix.put(pred * class_count + label, hist[nonzero])
return conf_matrix
check this one out,its quite vague without comments but should solve your issue