mAP的定义与概念
mAP:mean Average Precision,即各类别AP的平均值
AP:Average Precision,PR曲线下面积
PR曲线:Precision-Recall曲线
Precision:
Recall:
TP: 真正例,IoU>0.5的检测框的数量(同一Ground Truth只计算一次)
FP:假正例,IoU<=0.5的检测框,或者是检测到同一个GT的多余检测框的数量
FN:假负例,没有检测到的GT的数量
mAP的计算原理
根据前面的定义可知,如果我们想计算mAP,那我们必须首先绘制各类别PR曲线,从而计算出AP。而采样绘制PR曲线的方法,VOC采用过两种,主要以VOC2010为界限。
在VOC2010以前,只需要选取当Recall>=0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0共11个点时的Precision的最大值,然后AP就是这11个Precision的平均值。
在VOC2010及以后,需要针对每一个不同的Recall值(包括0和1),选取大于等于这些Recall值时的Precision的最大值,然后计算PR曲线下面积作为AP值
接下来举个例子,以apple类别为例,网络有如下输出,其中BB表示Bounding Box序号,IoU>0.5时,GT=1:
BB | confidence | GT
----------------------
BB1 | 0.9 | 1
----------------------
BB2 | 0.9 | 1
----------------------
BB1 | 0.8 | 1
----------------------
BB3 | 0.7 | 0
----------------------
BB4 | 0.7 | 0
----------------------
BB5 | 0.7 | 1
----------------------
BB6 | 0.7 | 0
----------------------
BB7 | 0.7 | 0
----------------------
BB8 | 0.7 | 1
----------------------
BB9 | 0.7 | 1
----------------------
因此,我们有 TP=5 (BB1, BB2, BB5, BB8, BB9), FP=5 (重复检测到的BB1也算FP)。除了表里检测到的5个GT以外,我们还有2个GT没被检测到,因此: FN = 2. 这时我们就可以按照Confidence的顺序给出各处的PR值,如下:
rank=1 precision=1.00 and recall=0.14
----------
rank=2 precision=1.00 and recall=0.29
----------
rank=3 precision=0.66 and recall=0.29
----------
rank=4 precision=0.50 and recall=0.29
----------
rank=5 precision=0.40 and recall=0.29
----------
rank=6 precision=0.50 and recall=0.43
----------
rank=7 precision=0.43 and recall=0.43
----------
rank=8 precision=0.38 and recall=0.43
----------
rank=9 precision=0.44 and recall=0.57
----------
rank=10 precision=0.50 and recall=0.71
对于上述PR值,如果我们采用:
1. VOC2010之前的方法,我们选取Recall >= 0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0 的11处的Precision的最大值:1,1,1,0.5,0.5,0.5,0.5,0.5,0,0,0,此时apple类别的AP=5.5/11=0.5
2. VOC2010之后的方法,我们选取Recall >= 0,0.14,0.29,0.43,0.57,0.71,1,我们选取此时Precision的最大值分别为1,1,1,0.5,0.5,0.5,0,此时apple类别的AP=(0.14-0)*1+(0.29-0.14)*1+(0.43-0.29)*0.5+(0.57-0.43)*0.5+(0.71-0.57)*0.5+(1-0.71)*0=0.5
而mAP就是对每个类别都计算AP,然后再计算AP的平均值就好了
参考链接:https://www.zhihu.com/question/53405779/answer/419532990