[英]What's the correct way to compute a confusion matrix for object detection?
我正在嘗試為我的對象檢測模型計算混淆矩陣。 但是,我似乎偶然發現了一些陷阱。 我目前的方法是將每個預測框與每個真實框進行比較。 如果他們的 IoU > 某個閾值,我將預測插入到混淆矩陣中。 插入后,我刪除預測列表中的元素並移至下一個元素。
因為我還希望將錯誤分類的提案插入到混淆矩陣中,所以我將 IoU 低於閾值的元素視為與背景混淆。 我當前的實現如下所示:
def insert_into_conf_m(true_labels, predicted_labels, true_boxes, predicted_boxes):
matched_gts = []
for i in range(len(true_labels)):
j = 0
while len(predicted_labels) != 0:
if j >= len(predicted_boxes):
break
if bb_intersection_over_union(true_boxes[i], predicted_boxes[j]) >= 0.7:
conf_m[true_labels[i]][predicted_labels[j]] += 1
del predicted_boxes[j]
del predicted_labels[j]
else:
j += 1
matched_gts.append(true_labels[i])
if len(predicted_labels) == 0:
break
# if there are ground-truth boxes that are not matched by any proposal
# they are treated as if the model classified them as background
if len(true_labels) > len(matched_gts):
true_labels = [i for i in true_labels if not i in matched_gts or matched_gts.remove(i)]
for i in range(len(true_labels)):
conf_m[true_labels[i]][0] += 1
# all detections that have no IoU with any groundtruth box are treated
# as if the groundtruth label for this region was Background (0)
if len(predicted_labels) != 0:
for j in range(len(predicted_labels)):
conf_m[0][predicted_labels[j]] += 1
行歸一化矩陣如下所示:
[0.0, 0.36, 0.34, 0.30]
[0.0, 0.29, 0.30, 0.41]
[0.0, 0.20, 0.47, 0.33]
[0.0, 0.23, 0.19, 0.58]
有沒有更好的方法來為對象檢測系統生成混淆矩陣? 或者任何其他更合適的指標?
這是一個腳本,用於從 TensorFlow 對象檢測 API 生成的 detections.record 文件中計算混淆矩陣。 這是解釋此腳本如何工作的文章。
總之,這里是文章中的算法大綱:
對於每個檢測記錄,該算法從輸入文件中提取真實框和類別,以及檢測到的框、類別和分數。
僅考慮得分大於或等於 0.5 的檢測。 低於此值的任何內容都將被丟棄。
對於每個真實框,該算法會為每個檢測到的框生成 IoU(聯合交集)。 如果兩個框的 IoU 大於或等於 0.5,則找到匹配項。
匹配列表被修剪以刪除重復項(與多個檢測框匹配的真實框,反之亦然)。 如果存在重復,則始終選擇最佳匹配(更大的 IoU)。
更新混淆矩陣以反映真實情況和檢測結果之間的匹配。
屬於ground-truth但未被檢測到的對象計入矩陣的最后一列(在對應於ground-truth類的行中)。 檢測到但不屬於混淆矩陣的對象計入矩陣的最后一行(在與檢測到的類別對應的列中)。
您還可以查看腳本以獲取更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.