Python 什么';计算目标检测混淆矩阵的正确方法是什么?
我试图为我的目标检测模型计算一个混淆矩阵。然而,我似乎偶然发现了一些陷阱。我目前的方法是将每个预测框与每个地面真相框进行比较。如果他们有一个IoU>某个阈值,我会将预测插入混淆矩阵。插入后,我删除预测列表中的元素,并继续下一个元素 因为我还希望将错误分类的建议插入混淆矩阵,所以我将IoU低于阈值的元素视为与背景混淆。我当前的实现如下所示:Python 什么';计算目标检测混淆矩阵的正确方法是什么?,python,object-detection,confusion-matrix,Python,Object Detection,Confusion Matrix,我试图为我的目标检测模型计算一个混淆矩阵。然而,我似乎偶然发现了一些陷阱。我目前的方法是将每个预测框与每个地面真相框进行比较。如果他们有一个IoU>某个阈值,我会将预测插入混淆矩阵。插入后,我删除预测列表中的元素,并继续下一个元素 因为我还希望将错误分类的建议插入混淆矩阵,所以我将IoU低于阈值的元素视为与背景混淆。我当前的实现如下所示: def insert_into_conf_m(true_labels, predicted_labels, true_boxes, predicted_box
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 groundtruth 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]
行规格化矩阵如下所示:
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 groundtruth 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文件计算混淆矩阵。解释这个脚本是如何工作的
总之,以下是文章中的算法概述:
您还可以查看更多信息。您能否解释如何使用提供的脚本计算每个类的真阳性、假阳性、假阴性和真阴性的数量