faster rcnn 中mAP、ap、precision和recall解析(多类平均正确率、平均正确率、精确率和召回率)

本文详细解析了FastRCNN中平均精度(AP)的计算方法,并对比了VOC2007与VOC2012的不同计算方式。介绍了如何通过召回率和精确率来确定AP值,包括11点平均法及积分法的具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://blog.youkuaiyun.com/a1154761720/article/details/50864994
https://blog.youkuaiyun.com/hysteric314/article/details/54093734
https://www.cnblogs.com/shixiangwan/p/7215926.html?utm_source=itdadao&utm_medium=referral请参考以上链接,你的疑惑就消除了。

P=检测正确/(检测正确+检测误以为正确)   R=检测正确/(检测正确+检测误以为错误)

下面我主要说一下faster rcnn关于ap的计算:

根目录lib/dataset 下voc_eval.py有这样的代码

def voc_ap(rec, prec, use_07_metric=False):
    """ ap = voc_ap(rec, prec, [use_07_metric])
    Compute VOC AP given precision and recall.
    If use_07_metric is true, uses the
    VOC 07 11 point method (default:False).
    """
    if use_07_metric:
        # 11 point metric
        ap = 0.
        for t in np.arange(0., 1.1, 0.1):
            if np.sum(rec >= t) == 0:
                p = 0
            else:
                p = np.max(prec[rec >= t])
            ap = ap + p / 11.
    else:
        # correct AP calculation
        # first append sentinel values at the end
        mrec = np.concatenate(([0.], rec, [1.]))
        mpre = np.concatenate(([0.], prec, [0.]))

        # compute the precision envelope
        for i in range(mpre.size - 1, 0, -1):
            mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i])

        # to calculate area under PR curve, look for points
        # where X axis (recall) changes value
        i = np.where(mrec[1:] != mrec[:-1])[0]

        # and sum (\Delta recall) * prec
        ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1])
    return ap

什么意思呢?如果你的数据集是voc2007,ap就取最大的精确率,11点取平均循环加起来。否则,比如数据集voc2012那么就使用precision和recall积分求面积得到ap。你可以把此法用到voc2007上也没有关系,我就是这样做的。

感谢三个链接作者对我的启发帮助!

mmdetection 是一个基于 PyTorch 的开源目标检测框架。在使用 mmdetection 训练模型时,通常在验证阶段会计算并显示精度(Precision)、召回率Recall)以及它们的综合指标,如平均精度均值(mAP)。 1. 精度(Precision):精度是指在所有被模型预测为正的样本中,真正为正的样本所占的比例。公式为:Precision = True Positives / (True Positives + False Positives)。 2. 召回率Recall):召回率是指在所有真实为正的样本中,被模型正确预测为正的样本所占的比例。公式为:Recall = True Positives / (True Positives + False Negatives)。 在 mmdetection 中,可以通过设置配置文件中的 `evaluation` 字段来指定评估指标,通常使用 COCO 数据集评估标准,会自动计算精度召回率。在训练过程中,每隔一定周期(由 `interval` 字段指定)会进行验证,并在控制台输出评估结果。如果要查看具体的精度召回率曲线,需要将验证的结果保存下来,并使用可视化工具进行绘制。 要显示精度召回率曲线,你可以使用以下步骤: - 在配置文件中确保 `evaluation` 字段已经设置好,例如: ```python evaluation = dict(interval=1, metric='bbox', save_best='mAP') ``` - 开始训练模型,并在训练日志中观察到似以下的输出(取决于所使用的评估标准): ```bash +-------+ | mmdet version | 2.4.0 | - | +---------------------+-------+---------------------+ | date time | | 2021-04-15_12:34:56 | +---------------------+-------+---------------------+ | #GPU | 4 | - | +---------------------+-------+---------------------+ | frameworks | | pytorch | +---------------------+-------+---------------------+ | task type | bbox | - | +---------------------+-------+---------------------+ | model type | faster_rcnn | - | +---------------------+-------+---------------------+ | checkpoint | | - | +---------------------+-------+---------------------+ | mode | train| - | +---------------------+-------+---------------------+ | #training samples | 11380| - | +---------------------+-------+---------------------+ | #test samples | 5000| - | +---------------------+-------+---------------------+ | start time | | 2021-04-15_12:34:58 | +-------+ | best mAP | 0.35 | - | +---------------------+-------+---------------------+ | epoch | 1 | - | +---------------------+-------+---------------------+ | iter | 1234| - | +---------------------+-------+---------------------+ | time elapsed | 120s | - | +---------------------+-------+---------------------+ | memory | 12345| - | +--+---------------------+ | lr | 0.0001| - | +---------------------+-------+---------------------+ | dataset/eval | | coco/bbox | +---------------------+-------+---------------------+ | dataset/samples | 5000| - | +---------------------+-------+---------------------+ | AP@0.5 | 0.35 | - | | AP@0.5:0.95 | 0.18 | - | | AP@0.50:0.95 | 0.18 | - | | AR@100 | 0.52 | - | | AR@300 | 0.57 | - | | AR@1000 | 0.57 | - | | AP_s@0.5 | 0.16 | - | | AP_s@0.5:0.95 | 0.09 | - | | AP_m@0.5 | 0.37 | - | | AP_m@0.5:0.95 | 0.20 | - | | AP_l@0.5 | 0.49 | - | | AP_l@0.5:0.95 | 0.25 | - | +-------+-------+---------------------+ ``` - 如果需要手动计算精度召回率曲线,可以编写脚本来分析验证集的结果文件,一般保存为 `.pkl` 或 `.json` 格式,然后绘制曲线。可以使用 matplotlib 等库来实现这一过程。 为了进一步了解如何使用 mmdetection 完成训练并评估模型,请参考其官方文档。
评论 38
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值