目标检测中的mAP

要计算mAP必须先绘出各类别PR曲线,计算出AP。而如何采样PR曲线,VOC采用过两种不同方法。
在VOC2010以前,只需要选取当Recall >= 0, 0.1, 0.2, …, 1共11个点时的Precision最大值,然后AP就是这11个Precision的平均值。
在VOC2010及以后,需要针对每一个不同的Recall值(包括0和1),选取其大于等于这些Recall值时的Precision最大值,然后计算PR曲线下面积作为AP值。

  • AP&mAP
    mAP:mean Average Precision,即各类别AP的平均值
    AP:PR曲线下面积
  • PR曲线
    PR曲线:Precision-Recall曲线
    Precision(查准率):TP / (TP + FP)
    Recall(查全率):TP / (TP + FN)

目标检测中的mAP
  • TP、FP、FN、TN
    TP(True Positive):IoU > IoU t h r e s h o l d {threshold}t h r e s h o l d ​(IoU t h r e s h o l d {threshold}t h r e s h o l d ​一般取 0.5)的检测框数量(同一Ground Truth只计算一次)
    FP(False Positive):IoU
  • 交并比(IoU)
    IoU(Intersection Over Union):指真实框和预测框之间交集和并集的比。假设这里有真实框B g t B_{gt}B g t ​和预测框B p B_p B p ​,那么 IoU计算公式如下:
    目标检测中的mAP
    目标检测中的mAP
  • 评价指标mAP
    下面用一个例子说明AP和mAP的计算。先规定两个公式,一个是Precision,一个是Recall,这两个公式同上面的一样,我们把它们扩展开来,用另外一种形式进行展示,如下所示。
    目标检测中的mAP
    AP是计算某一类P-R曲线下的面积,mAP则是计算所有类别P-R 曲线下面积的平均值。
    假设我们有7张图片(Images1-Image7),这些图片有15个目标(绿色的框,GT的数量,上文提及的all ground truths)以及24个预测边框(红色的框,A-Y编号表示,并且有一个置信度值),如下图所示。
    目标检测中的mAP
    目标检测中的mAP
    目标检测中的mAP
    标号2:Precision=TP/(TP+FP)=1/(1+1)=0.5,Recall=TP/(TP+FN)=TP/(all ground truths)=1/15=0.0666
    标号3:Precision=TP/(TP+FP)=2/(2+1)=0.6666,Recall=TP/(TP+FN)=TP/(all ground truths)=2/15=0.1333
    标号4:Precision=TP/(TP+FP)=2/(2+2)=0.5,Recall=TP/(TP+FN)=TP/(all ground truths)=2/15=0.1333
    标号5:Precision=TP/(TP+FP)=2/(2+3)=0.4,Recall=TP/(TP+FN)=TP/(all ground truths)=2/15=0.1333
    标号6:Precision=TP/(TP+FP)=2/(2+4)=0.3333,Recall=TP/(TP+FN)=TP/(all ground truths)=2/15=0.1333
    标号7:Precision=TP/(TP+FP)=2/(2+5)=0.2857,Recall=TP/(TP+FN)=TP/(all ground truths)=2/15=0.1333
    标号8:Precision=TP/(TP+FP)=2/(2+6)=0.25,Recall=TP/(TP+FN)=TP/(all ground truths)=2/15=0.1333
    标号9:Precision=TP/(TP+FP)=2/(2+7)=0.2222,Recall=TP/(TP+FN)=TP/(all ground truths)=2/15=0.1333
    标号10:Precision=TP/(TP+FP)=3/(3+7)=0.3,Recall=TP/(TP+FN)=TP/(all ground truths)=3/15=0.2
    标号11:Precision=TP/(TP+FP)=3/(3+8)=0.2727,Recall=TP/(TP+FN)=TP/(all ground truths)=3/15=0.2
    标号12:Precision=TP/(TP+FP)=4/(4+8)=0.3333,Recall=TP/(TP+FN)=TP/(all ground truths)=4/15=0.2666
    标号13:Precision=TP/(TP+FP)=5/(5+8)=0.3846,Recall=TP/(TP+FN)=TP/(all ground truths)=5/15=0.3333
    标号14:Precision=TP/(TP+FP)=6/(6+8)=0.4285,Recall=TP/(TP+FN)=TP/(all ground truths)=6/15=0.4
    标号15:Precision=TP/(TP+FP)=6/(6+9)=0.45,Recall=TP/(TP+FN)=TP/(all ground truths)=6/15=0.4
    标号16:Precision=TP/(TP+FP)=6/(6+10)=0.375,Recall=TP/(TP+FN)=TP/(all ground truths)=6/15=0.4
    标号17:Precision=TP/(TP+FP)=6/(6+11)=0.3529,Recall=TP/(TP+FN)=TP/(all ground truths)=6/15=0.4
    标号18:Precision=TP/(TP+FP)=6/(6+12)=0.3333,Recall=TP/(TP+FN)=TP/(all ground truths)=6/15=0.4
    标号19:Precision=TP/(TP+FP)=6/(6+13)=0.3157,Recall=TP/(TP+FN)=TP/(all ground truths)=6/15=0.4
    标号20:Precision=TP/(TP+FP)=6/(6+14)=0.3,Recall=TP/(TP+FN)=TP/(all ground truths)=6/15=0.4
    标号21:Precision=TP/(TP+FP)=6/(6+15)=0.2857,Recall=TP/(TP+FN)=TP/(all ground truths)=6/15=0.4
    标号22:Precision=TP/(TP+FP)=6/(6+16)=0.2727,Recall=TP/(TP+FN)=TP/(all ground truths)=6/15=0.4
    标号23:Precision=TP/(TP+FP)=7/(7+16)=0.3043,Recall=TP/(TP+FN)=TP/(all ground truths)=7/15=0.4666
    标号24:Precision=TP/(TP+FP)=7/(7+17)=0.2916,Recall=TP/(TP+FN)=TP/(all ground truths)=7/15=0.4666
    然后就可以绘制出P-R曲线,如下图所示。
    目标检测中的mAP
    目标检测中的mAP

目标检测中的mAP
A 1 = ( 0.0666 − 0 ) × 1 = 0.0666 A1 = (0.0666-0) \times 1 = 0.0666 A 1 =(0 .0 6 6 6 −0 )×1 =0 .0 6 6 6
A 2 = ( 0.1333 − 0.0666 ) × 0.0666 = 0.04446222 A2 = (0.1333-0.0666) \times 0.0666 = 0.04446222 A 2 =(0 .1 3 3 3 −0 .0 6 6 6 )×0 .0 6 6 6 =0 .0 4 4 4 6 2 2 2
A 3 = ( 0.4 − 0.1333 ) × 0.4285 = 0.11428095 A3 = (0.4−0.1333) \times 0.4285 = 0.11428095 A 3 =(0 .4 −0 .1 3 3 3 )×0 .4 2 8 5 =0 .1 1 4 2 8 0 9 5
A 4 = ( 0.4666 − 0.40 ) × 0.3043 = 0.02026638 A4 = (0.4666−0.40) \times 0.3043 = 0.02026638 A 4 =(0 .4 6 6 6 −0 .4 0 )×0 .3 0 4 3 =0 .0 2 0 2 6 6 3 8
A P = A 1 + A 2 + A 3 + A 4 = 0.0666 + 0.04446222 + 0.11428095 + 0.02026638 = 0.2456095 = 24.56 % AP = A1 + A2 + A3 + A4 = 0.0666+0.04446222+0.11428095+0.02026638=0.2456095=24.56\%A P =A 1 +A 2 +A 3 +A 4 =0 .0 6 6 6 +0 .0 4 4 4 6 2 2 2 +0 .1 1 4 2 8 0 9 5 +0 .0 2 0 2 6 6 3 8 =0 .2 4 5 6 0 9 5 =2 4 .5 6 %
mAP就是对每一个类别都计算出AP然后再计算AP平均值就好了。

参考文章:https://www.zhihu.com/question/53405779/answer/993913699
https://blog.csdn.net/chris_xy/article/details/103036756

Original: https://blog.csdn.net/HUAI_BI_TONG/article/details/121212733
Author: 大彤小忆
Title: 目标检测中的mAP

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/629590/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球