目标检测之mAP指标笔记

记录在CSDN博客上看到的关于mAP讲解的精彩内容

首先作为目标检测的重要通用指标mAP,用于衡量算法模型对于数据集中指定目标进行检测的准确程度,这个准确程度有两层含义:第一个指分类的精确程度(pricision);第二个指预测框的准确程度(IOU)。
一般理解mAP需要先理解什么是pricision,什么是recall,这个可以看文末的博客,有很生动的例子,而且其来源是基于检索模型的metric,根据不同的查询结果(多个rank),不同的query序列的PR曲线进行计算得来。
目标检测的mAP计算,是将模型的输出(被认为是一个包含分类结果,confidence置信度,与目标框坐标的rank list)的所有判断为正例的精确度(AP),进行多目标的平均,即mAP。

计算mAP的python代码:

def voc_ap(self, rec, prec, use_07_metric=True):
    if use_07_metric:
        ap = 0.
        # 2010年以前按recall等间隔取11个不同点处的精度值做平均(0., 0.1, 0.2, …, 0.9, 1.0)
        for t in np.arange(0., 1.1, 0.1):
            if np.sum(rec >= t) == 0:
                p = 0
            else:
                # 取最大值等价于2010以后先计算包络线的操作,保证precise非减
                p = np.max(prec[rec >= t])
            ap = ap + p / 11.
    else:
        # 2010年以后取所有不同的recall对应的点处的精度值做平均
        # first append sentinel values at the end
        mrec = np.concatenate(([0.], rec, [1.]))
        mpre = np.concatenate(([0.], prec, [0.]))

        # 计算包络线,从后往前取最大保证precise非减
        for i in range(mpre.size - 1, 0, -1):
            mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i])

        # 找出所有检测结果中recall不同的点
        i = np.where(mrec[1:] != mrec[:-1])[0]

        # and sum (\Delta recall) * prec
        # 用recall的间隔对精度作加权平均
        ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1])
    return ap

内容通过阅读以下文章进行总结:
https://blog.csdn.net/asasasaababab/article/details/79994920

http://tarangshah.com/blog/2018-01-27/what-is-map-understanding-the-statistic-of-choice-for-comparing-object-detection-models/

猜你喜欢

转载自blog.csdn.net/qq_34606546/article/details/85569555