【深度学习】如何计算AP(平均精度)和mAP(平均精度均值)?

起因:最近导师给买了本书,叫做《智能计算系统》(陈云霁等人编著),让我上b站看看教材对应的视频。不得不说这书写的确实不错,b站上的视频讲的也还可以。书和视频的内容可以相互补充,比如视频对于一些细节讲的不清楚,看一下书对应的部分就能了解得差不多。书讲的不清楚的地方就可以按照标注的附录去找原材料,基本就能搞懂~

所以先推荐一波书+视频,有兴趣的可以看看~

【深度学习】如何计算AP(平均精度)和mAP(平均精度均值)?_第1张图片

b站视频链接:

https://www.bilibili.com/video/BV1WE411A7tv

我现在刚看到第三章,讲到计算AP和mAP的地方不太明白,就去书上标注的附录找到援引的文件,在这里附上链接:

http://host.robots.ox.ac.uk/pascal/VOC/voc2012/devkit_doc.pdf

 

①首先介绍一下Recall(召回率/查全率)和Precision(精度/查准率):

以一张图片物体检测为例,检测算法框出N=1000个框,正确检测出物体A的框有k=50个,实际上图片中有M=100个物体A:

Recall = k / M

Precision = k / N

Recall和Precision之间是有关系的,如果大幅度增加检测框,比如增加100万个框,此时k↑,M→,N↑↑,那么召回率↑、精度↓

于是引入AP,来衡量测试集中某一个类的分类误差,并体现召回率和精度。

②那么接下来,怎么计算AP?(我用书上的图做一个说明哈)

【深度学习】如何计算AP(平均精度)和mAP(平均精度均值)?_第2张图片

我看到视频弹幕里有人问Recall=4/25时,对应的最大Precision不应该是4/9吗?为什么是6/13?

其实是这样的哈,视频和书在这一点上没有讲清楚。原本规则是对应同一个Recall的Precision取最大,同时要保证得到的最大Precision是单调递减的(precision monotonically decreasing)。

Recall=4/25 → Max Precision=4/9=0.4444

Recall=5/25 → Max Precision=5/12=0.4167

Recall=6/25 → Max Precision=6/13=0.4615

可以看出这三个里面的Max Precision最大是0.4615(6/13),因此选择6/13作为这三个的Max Precision才能保证曲线单调递减。

如果……→Recall=3/25(Max Precision=3/4)→Recall=4/25(Max Precision=4/9)→Recall=5/25(Max Precision=5/12)→Recall=6/25(Max Precision=6/13)→……

你会发现得到的曲线在Recall=5/25→Recall=6/25上升了,这违反了单调递减的规则。

③这一点搞懂以后,我们就能绘制出对应的曲线,在上图3.24中用蓝色的分段常数表示。

④AP = 蓝色曲线对Recall求积分(面积)

因为这个曲线是分段常数的形式,所以就是几个矩阵面积求和:

AP = ( 1 + 1 + 3/4 + 6/13 + 6/13 + 6/13 + 7/17) * (1/25) = 0.1819

⑤AP是对一种类别求平均精度,而mAP是对所有种类求平均精度,也就是所有AP加起来求个平均值:

 (\sum_{c=1}^{C}AP_{c})/C     (C是图像检测的类别数)

 

最后贴一下材料对应的原文(链接在文章开头写了):

3.4.1 Average Precision (AP)

The computation of the average precision (AP) measure was changed in 2010 to improve precision and ability to measure differences between methods with low AP. It is computed as follows:

1. Compute a version of the measured precision/recall curve with precision monotonically decreasing, by setting the precision for recall r to the maximum precision obtained for any recall r ′ ≥ r.

2. Compute the AP as the area under this curve by numerical integration. No approximation is involved since the curve is piecewise constant.

Note that prior to 2010 the AP is computed by sampling the monotonically decreasing curve at a fixed set of uniformly-spaced recall values 0, 0.1, 0.2, . . . , 1. By contrast, VOC2010–2012 effectively samples the curve at all unique recall values.

你可能感兴趣的:(AI,深度学习,计算机视觉)