【问题标题】:What's the correct way to compute a confusion matrix for object detection?计算对象检测的混淆矩阵的正确方法是什么?
【发布时间】:2018-02-17 00:43:07
【问题描述】:

我正在尝试为我的对象检测模型计算混淆矩阵。但是,我似乎偶然发现了一些陷阱。我目前的方法是将每个预测框与每个真实框进行比较。如果他们的 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 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]

有没有更好的方法来为对象检测系统生成混淆矩阵?还是其他更合适的指标?

【问题讨论】:

    标签: python object-detection confusion-matrix


    【解决方案1】:

    Here is a script 从 TensorFlow Object Detection API 生成的 detections.record 文件中计算混淆矩阵。 Here is the article 解释这个脚本是如何工作的。

    总之,这里是文章中的算法大纲:

    1. 对于每个检测记录,算法从输入文件中提取真实框和类别,以及检测到的 框、课程和分数。

    2. 仅考虑得分大于或等于 0.5 的检测。低于此值的任何内容都将被丢弃。

    3. 对于每个真实框,算法会与每个检测到的框生成 IoU(联合交集)。如果找到匹配项 两个框的 IoU 都大于或等于 0.5。

    4. 对匹配列表进行修剪以删除重复项(与多个检测框匹配的真实框,反之亦然)。如果 有重复,总是选择最佳匹配(更大的 IoU)。

    5. 更新混淆矩阵以反映真实情况和检测结果之间的匹配。

    6. 属于真实情况但未被检测到的对象计入矩阵的最后一列(对应于 地面实况类)。检测到但不属于其中的对象 混淆矩阵计算在矩阵的最后一行(在 对应于检测到的类别的列)。

    您也可以查看at the script 了解更多信息。

    【讨论】:

    • 你能解释一下如何使用提供的脚本计算每个类的真阳性、假阳性、假阴性和真阴性的数量
    猜你喜欢
    • 2020-03-23
    • 2018-04-01
    • 2019-12-05
    • 2017-02-25
    • 2019-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多