簡體   English   中英

如何在Python中計算分段的類聯合(IOU)?

[英]How to compute class intersection over union (IOU) for segmentaion in Python?

我為每個圖像(汽車/人/人行道)有多個類的numpy數組,如何有效地計算每個類的IOU和所有類的平均IOU?

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

看看這個,它很模糊,沒有評論,但應該解決您的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM