0


目标检测评价指标Precision、Recall、mAP

目标检测评价指标Precision、Recall、mAP

参考:
Object-Detection-Metrics
A Survey on Performance Metrics for Object-Detection Algorithms

1.重要定义

1.1.交并比(IOU)

Intersection Over Union (IOU)交并比用来衡量两个框的重合率,其计算公式如下:

       I 
      
     
       O 
      
     
       U 
      
     
    
      = 
     
     
      
      
        area 
       
      
        ⁡ 
       
       
       
         ( 
        
        
        
          B 
         
        
          p 
         
        
       
         ∩ 
        
        
        
          B 
         
         
         
           g 
          
         
           t 
          
         
        
       
         ) 
        
       
      
      
      
        area 
       
      
        ⁡ 
       
       
       
         ( 
        
        
        
          B 
         
        
          p 
         
        
       
         ∪ 
        
        
        
          B 
         
         
         
           g 
          
         
           t 
          
         
        
       
         ) 
        
       
      
     
    
   
     \mathrm{IOU}=\frac{\operatorname{area}\left(B_{p} \cap B_{g t}\right)}{\operatorname{area}\left(B_{p} \cup B_{g t}\right)} 
    
   
 IOU=area(Bp​∪Bgt​)area(Bp​∩Bgt​)​

其中

      B 
     
    
      p 
     
    
   
  
    B_{p} 
   
  
Bp​为模型预测的框, 
 
  
   
    
    
      B 
     
     
     
       g 
      
     
       t 
      
     
    
   
  
    B_{g t} 
   
  
Bgt​为ground truth。直观点:

在这里插入图片描述

实验评估过程中会设置一项IOU阀值,用来评判

      B 
     
    
      p 
     
    
   
  
    B_{p} 
   
  
Bp​为正样本或负样本,例如设置IOU阀值为0.5,代表:
  • IOU ≥ 0.5 : B p B_{p} Bp​为正样本;
  • IOU < 0.5 : B p B_{p} Bp​为负样本。

阀值经常被设为50%, 75%或95%。

1.2.TP , FP , FN

  • True Positive (TP) : 一次正确的检测,即 B p B_{p} Bp​与 B g t B_{g t} Bgt​的IOU ≥ threshold(初始设定的IOU阀值);
  • False Positive (FP) :一次错误的检测,代表模型预测的 B p B_{p} Bp​与真值 B g t B_{g t} Bgt​的IOU < threshold;
  • False Negative (FN) : 代表真值 B g t B_{g t} Bgt​没有被检测出来,即模型预测的所有 B p B_{p} Bp​里没有与该 B g t B_{g t} Bgt​重合的;

1.3.Precision(准确率),Recall(召回率)

  • Precision(准确率):指模型在一张图片上预测的所有框中,为正确检测的比率,表达式 Precision = T P T P + F P = T P all detections \text { Precision }=\frac{\mathrm{TP}}{\mathrm{TP}+\mathrm{FP}}=\frac{\mathrm{TP}}{\text { all detections }} Precision =TP+FPTP​= all detections TP​
  • Recall(召回率):指所有ground truth中被正确匹配到的比率 Recall = T P T P + F N = T P all ground truths \text { Recall }=\frac{\mathrm{TP}}{\mathrm{TP}+\mathrm{FN}}=\frac{\mathrm{TP}}{\text { all ground truths }} Recall =TP+FNTP​= all ground truths TP​

2.Average Precision(AP)

AP 是0到1之间的所有Recall对应的Precision的平均值。从Precision和Recall的公式可以看出,随着模型在图片上预测的框(all detections)越多,而TP会有上限,所以对应的Precision会变小;当all detections越多,就代表有越多的ground truth可能会被正确匹配,即TP会有少量增加,此时Recall会变大。反过来也一样,所以我们需要检测器保持随着Recall增加(越来越多的ground truth被正确匹配),Precision也保持较高准确率。

Average Precision (AP)用来计算Precision x Recall曲线的面积,如下图所示,方式是插值法。
在这里插入图片描述

以上参考文章中有举例,这里进行分析:

在这里插入图片描述
这里共有7幅图像,其中绿色边界框表示15个ground truth,红色边界框表示24个pre-box。每一个预测的框pre-box都包含一个置信度。接下来的表格展示了每一个pre-box和对应置信度,需注意:

  • 只要一个pre-box与某个ground truth的IOU大于设定阈值,则标记为TP,否则为FP。
  • 在一些图片上,一个ground truth与不止一个pre-box有重合,则与其IOU最大的pre-box为TP,其余为FP。在这里插入图片描述

因为Precision和Recall都是靠FP,TP来计算的,所以Precision x Recall 曲线也是通过计算累积的 TP 或 FP 检测的准确率召回率值绘制的。首先,我们需要根据检测的可信度来排序,然后计算每个累积检测的Precision和Recall,如下表所示:
在这里插入图片描述
其中Acc TP是累计出现了几个TP。根据当前的Acc TP和Acc FP计算当前的Precision和Recall。画出来折线图:
在这里插入图片描述
上文提到用插值法计算AP,这里有两种插值方法:

2.1 11点插值

计算公式:

       A 
      
     
       P 
      
     
    
      = 
     
     
     
       1 
      
     
       11 
      
     
     
     
       ∑ 
      
      
      
        r 
       
      
        ∈ 
       
      
        { 
       
      
        0 
       
      
        , 
       
      
        0.1 
       
      
        , 
       
      
        … 
       
      
        , 
       
      
        1 
       
      
        } 
       
      
     
     
     
       ρ 
      
      
      
        interp 
       
      
        ⁡ 
       
      
        ( 
       
      
        r 
       
      
        ) 
       
      
     
    
   
     \mathrm{AP}=\frac{1}{11} \sum_{r \in\{0,0.1, \ldots, 1\}} \rho_{\operatorname{interp}(r)} 
    
   
 AP=111​r∈{0,0.1,…,1}∑​ρinterp(r)​

其中

       ρ 
      
     
       interp  
      
     
    
      = 
     
     
      
      
        max 
       
      
        ⁡ 
       
      
      
       
       
         r 
        
       
         ˉ 
        
       
      
        : 
       
       
       
         r 
        
       
         ~ 
        
       
      
        ≥ 
       
      
        r 
       
      
     
    
      ρ 
     
    
      ( 
     
     
     
       r 
      
     
       ~ 
      
     
    
      ) 
     
    
   
     \rho_{\text {interp }}=\max _{\bar{r}: \tilde{r} \geq r} \rho(\tilde{r}) 
    
   
 ρinterp ​=rˉ:r~≥rmax​ρ(r~)

该公式的含义是在11个level的recall下,即

     r 
    
   
     ∈ 
    
   
     { 
    
   
     0 
    
   
     , 
    
   
     0.1 
    
   
     , 
    
   
     … 
    
   
     , 
    
   
     1 
    
   
     } 
    
   
  
    r \in\{0,0.1, \ldots,1\} 
   
  
r∈{0,0.1,…,1}下,进行插值。例如:
  • 当 r = 0 r=0 r=0时, ρ interp = max ⁡ r ˉ : r ~ ≥ 0 ρ ( r ~ ) \rho_{\text {interp }}=\max _{\bar{r}: \tilde{r} \geq 0} \rho(\tilde{r}) ρinterp ​=maxrˉ:r≥0​ρ(r),而在所有 r ~ ≥ 0 \tilde{r} \geq 0 r≥0的点中,能令 ρ ( r ~ ) \rho(\tilde{r}) ρ(r)最大的 r ~ \tilde{r} r~为其等于0.0666时,此时Precision=1。
  • 当 r = 0.1 r=0.1 r=0.1时, ρ interp = max ⁡ r ˉ : r ~ ≥ 0.1 ρ ( r ~ ) \rho_{\text {interp }}=\max _{\bar{r}: \tilde{r} \geq 0.1} \rho(\tilde{r}) ρinterp ​=maxrˉ:r≥0.1​ρ(r),在所有 r ~ ≥ 0.1 \tilde{r} \geq 0.1 r≥0.1的点中,能令 ρ ( r ~ ) \rho(\tilde{r}) ρ(r)最大的 r ~ \tilde{r} r~为其等于0.1333时,此时Precision=0.6666。
  • 以此类推,没有 r > = 0.5 r>=0.5 r>=0.5的情况,所以之后为0,得到下式: A P = 1 11 ∑ r ∈ { 0 , 0.1 , … , 1 } ρ interp ( r ) A P = 1 11 ( 1 + 0.6666 + 0.4285 + 0.4285 + 0.4285 + 0 + 0 + 0 + 0 + 0 + 0 ) A P = 26.84 % \begin{array}{l} A P=\frac{1}{11} \sum_{r \in{0,0.1, \ldots, 1}} \rho_{\text {interp }(r)} \ A P=\frac{1}{11}(1+0.6666+0.4285+0.4285+0.4285+0+0+0+0+0+0) \ A P=26.84 % \end{array} AP=111​∑r∈{0,0.1,…,1}​ρinterp (r)​AP=111​(1+0.6666+0.4285+0.4285+0.4285+0+0+0+0+0+0)AP=26.84%​

2.1 全点插值

这个看图很好理解,即计算面积:
在这里插入图片描述
在这里插入图片描述
计算公式:

          A 
         
        
          P 
         
        
          = 
         
         
         
           A 
          
         
           1 
          
         
        
          + 
         
         
         
           A 
          
         
           2 
          
         
        
          + 
         
         
         
           A 
          
         
           3 
          
         
        
          + 
         
         
         
           A 
          
         
           4 
          
         
        
       
      
     
     
      
       
        
         
         
           A 
          
         
           1 
          
         
        
          = 
         
        
          ( 
         
        
          0.0666 
         
        
          − 
         
        
          0 
         
        
          ) 
         
        
          × 
         
        
          1 
         
        
          = 
         
        
          0.0666 
         
        
       
      
     
     
      
       
        
         
         
           A 
          
         
           2 
          
         
        
          = 
         
        
          ( 
         
        
          0.1333 
         
        
          − 
         
        
          0.0666 
         
        
          ) 
         
        
          × 
         
        
          0.6666 
         
        
          = 
         
        
          0.04446222 
         
        
       
      
     
     
      
       
        
         
         
           A 
          
         
           3 
          
         
        
          = 
         
        
          ( 
         
        
          0.4 
         
        
          − 
         
        
          0.1333 
         
        
          ) 
         
        
          × 
         
        
          0.4285 
         
        
          = 
         
        
          0.11428095 
         
        
       
      
     
     
      
       
        
         
         
           A 
          
         
           4 
          
         
        
          = 
         
        
          ( 
         
        
          0.4666 
         
        
          − 
         
        
          0.4 
         
        
          ) 
         
        
          × 
         
        
          0.3043 
         
        
          = 
         
        
          0.02026638 
         
        
       
      
     
     
      
       
        
        
          A 
         
        
          P 
         
        
          = 
         
        
          0.0666 
         
        
          + 
         
        
          0.04446222 
         
        
          + 
         
        
          0.11428095 
         
        
          + 
         
        
          0.02026638 
         
        
       
      
     
     
      
       
        
        
          A 
         
        
          P 
         
        
          = 
         
        
          0.24560955 
         
        
       
      
     
     
      
       
        
        
          A 
         
        
          P 
         
        
          = 
         
        
          24.56 
         
        
          % 
         
        
       
      
     
    
   
     \begin{array}{l} A P=A _1+A _2+A _3+A _4\\ A _1=(0.0666-0) \times 1=\mathbf{0 . 0 6 6 6} \\ A_ 2=(0.1333-0.0666) \times 0.6666=\mathbf{0 . 0 4 4 4 6 2 2 2} \\ A _3=(0.4-0.1333) \times 0.4285=\mathbf{0 . 1 1 4 2 8 0 9 5} \\ A _4=(0.4666-0.4) \times 0.3043=\mathbf{0 . 0 2 0 2 6 6 3 8} \\ A P=0.0666+0.04446222+0.11428095+0.02026638 \\ A P=0.24560955 \\ A P=\mathbf{2 4 . 5 6} \% \end{array} 
    
   
 AP=A1​+A2​+A3​+A4​A1​=(0.0666−0)×1=0.0666A2​=(0.1333−0.0666)×0.6666=0.04446222A3​=(0.4−0.1333)×0.4285=0.11428095A4​=(0.4666−0.4)×0.3043=0.02026638AP=0.0666+0.04446222+0.11428095+0.02026638AP=0.24560955AP=24.56%​

本文转载自: https://blog.csdn.net/weixin_45453121/article/details/129737434
版权归原作者 Facias 所有, 如有侵权,请联系我们删除。

“目标检测评价指标Precision、Recall、mAP”的评论:

还没有评论