当前位置:   article > 正文

目标检测指标_目标检测检出检准公式

目标检测检出检准公式

IOU (Intersection Over Union, 交并比)

IOU指真实框和预测框之间交集和并集的比,假设这里有真实框B g t B_{gt}Bgt​和预测框B p B_pBp​,那么 IOU计算公式如下:
I O U = a r e a ( B p ∩ B g t ) a r e a ( B p ∪ B g t ) IOU=\frac{area(B_p\cap B_{gt})}{area(B_p\cup B_{gt})}IOU=area(Bp​∪Bgt​)area(Bp​∩Bgt​)​

有了IOU的计算公式,我们就可以来计算 TP、FP、FN、TN

这里会用到threshold交并比的阈值,通常取50%、75%、95%

  • True Positive(TP): 一个目标框被正确检测出来,I O U ≥ t h r e s h o l d IOU \ge thresholdIOUthreshold
  • False Positive(FP): 预测框预测错误,I O U < t h r e s h o l d IOU < thresholdIOU<threshold
  • False Negative(FN): 一个目标框没有被预测出来
  • True Negative(TN): 在这里不适用。

Precision精确率

precision指正确检测出来的目标框数量占所有预测目标框数量的比例。
P r e c i s i o n = T P T P + F P = T P a l l _ d e t e c t i o n s Precision = \frac{TP}{TP+FP}=\frac{TP}{all\_detections}Precision=TP+FPTP​=all_detectionsTP

Recall召回率

recall指正确检测出来的目标框数量占所有真实目标框数量的比例。
R e c a l l = T P T P + F N = T P a l l _ g r o u n d _ t r u t h s Recall = \frac{TP}{TP+FN}=\frac{TP}{all\_ground\_truths}Recall=TP+FNTP​=all_ground_truthsTP

Precision x Recall curve, PR曲线

以精确率为y轴,以召回率为x轴,我们就得到了PR曲线。仍然从精确率和召回率的定义可以理解,精确率越高,召回率越高,我们的模型和算法就越高效。也就是画出来的PR曲线越靠近右上越好。

Average Precision,AP

PR曲线下面的面积。假设一共有N中recall的取值,计算公式如下:

A P = ∑ n = 1 N ( r n + 1 − r n ) ρ i n t e r p ( r n + 1 ) ρ i n t e r p ( r n + 1 ) = m a x r ^ = r n + 1 ρ ( r ^ ) AP=\sum_{n=1}^{N}(r_{n+1}-r_n)\rho_{interp}(r_{n+1})\\ \rho_{interp}(r_{n+1})= max_{\hat r=r_{n+1}} \rho(\hat r)AP=n=1∑N​(rn+1​−rn​)ρinterp​(rn+1​)ρinterp​(rn+1​)=maxr^=rn+1​​ρ(r^)

其中r n r_nrn​代表第n个recall的取值,ρ ( r ) \rho(r)ρr)代表在recall为r下对应precision的取值。具体解释如下,当我们取到第n种recall的取值,然后又出现了第n+1种recall的取值,我们在这个recall区间里找到对应最大值的precision,并用这个最大的precision乘上这段recall的取值范围为这个recall区间的AP,我们遍历所有区间并把所有区间的AP加起来就得到了最终的AP

为了更清楚的对这些概念进行说明,举例如下:

这里有7张图片15个目标框24个预测框,这里目标框和预测框都为同一类别。其中目标框用绿色表示,预测框用红色表示。这里设置threshold为30%,TP和FP的取值是按照IOU计算得到,跟Confidences无关。表格如下:

ImageDetectionsConfidencesTP or FP
Image1A88%FP
Image1B70%TP
Image1C80%FP
Image2D71%FP
Image2E54%TP
Image2F74%FP
Image3G18%TP
Image3H67%FP
Image3I38%FP
Image3J91%TP
Image3K44%FP
Image4L35%FP
Image4M78%FP
Image4N45%FP
Image4O14%FP
Image5P62%TP
Image5Q44%FP
Image5R95%TP
Image5S23%FP
Image6T45%FP
Image6U84%FP
Image6V43%FP
Image7X48%TP
Image7Y95%FP

有了这些值,我们就开始按照Confidences大小排序来计算Precision和Recall值:

ImageDetectionsConfidencesTP or FPPrecisionRecall
Image5R95%TP1 1 = 1 \frac{1}{1}=111​=11 15 = 0.0666 \frac{1}{15}=0.0666151​=0.0666
Image7Y95%FP1 2 = 0.5 \frac{1}{2}=0.521​=0.51 15 = 0.0666 \frac{1}{15}=0.0666151​=0.0666
Image3J91%TP2 3 = 0.6666 \frac{2}{3}=0.666632​=0.66662 15 = 0.1333 \frac{2}{15}=0.1333152​=0.1333
Image1A88%FP2 4 = 0.5 \frac{2}{4}=0.542​=0.52 15 = 0.1333 \frac{2}{15}=0.1333152​=0.1333
Image6U84%FP2 5 = 0.4 \frac{2}{5}=0.452​=0.42 15 = 0.1333 \frac{2}{15}=0.1333152​=0.1333
Image1C80%FP2 6 = 0.3333 \frac{2}{6}=0.333362​=0.33332 15 = 0.1333 \frac{2}{15}=0.1333152​=0.1333
Image4M78%FP2 7 = 0.2857 \frac{2}{7}=0.285772​=0.28572 15 = 0.1333 \frac{2}{15}=0.1333152​=0.1333
Image2F74%FP2 8 = 0.25 \frac{2}{8}=0.2582​=0.252 15 = 0.1333 \frac{2}{15}=0.1333152​=0.1333
Image2D71%FP2 9 = 0.2222 \frac{2}{9}=0.222292​=0.22222 15 = 0.1333 \frac{2}{15}=0.1333152​=0.1333
Image1B70%TP3 10 = 0.3 \frac{3}{10}=0.3103​=0.33 15 = 0.2 \frac{3}{15}=0.2153​=0.2
Image3H67%FP3 11 = 0.2727 \frac{3}{11}=0.2727113​=0.27273 15 = 0.2 \frac{3}{15}=0.2153​=0.2
Image5P62%TP4 12 = 0.3333 \frac{4}{12}=0.3333124​=0.33334 15 = 0.2666 \frac{4}{15}=0.2666154​=0.2666
Image2E54%TP5 13 = 0.3846 \frac{5}{13}=0.3846135​=0.38465 15 = 0.3333 \frac{5}{15}=0.3333155​=0.3333
Image7X48%TP6 14 = 0.4285 \frac{6}{14}=0.4285146​=0.42856 15 = 0.4 \frac{6}{15}=0.4156​=0.4
Image4N45%FP6 15 = 0.45 \frac{6}{15}=0.45156​=0.456 15 = 0.4 \frac{6}{15}=0.4156​=0.4
Image6T45%FP6 16 = 0.375 \frac{6}{16}=0.375166​=0.3756 15 = 0.4 \frac{6}{15}=0.4156​=0.4
Image3K44%FP6 17 = 0.3529 \frac{6}{17}=0.3529176​=0.35296 15 = 0.4 \frac{6}{15}=0.4156​=0.4
Image5Q44%FP6 18 = 0.3333 \frac{6}{18}=0.3333186​=0.33336 15 = 0.4 \frac{6}{15}=0.4156​=0.4
Image6V43%FP6 19 = 0.3157 \frac{6}{19}=0.3157196​=0.31576 15 = 0.4 \frac{6}{15}=0.4156​=0.4
Image3I38%FP6 20 = 0.3 \frac{6}{20}=0.3206​=0.36 15 = 0.4 \frac{6}{15}=0.4156​=0.4
Image4L35%FP6 21 = 0.2857 \frac{6}{21}=0.2857216​=0.28576 15 = 0.4 \frac{6}{15}=0.4156​=0.4
Image5S23%FP6 22 = 0.2727 \frac{6}{22}=0.2727226​=0.27276 15 = 0.4 \frac{6}{15}=0.4156​=0.4
Image3G18%TP7 23 = 0.3043 \frac{7}{23}=0.3043237​=0.30437 15 = 0.4666 \frac{7}{15}=0.4666157​=0.4666
Image4O14%FP7 24 = 0.2916 \frac{7}{24}=0.2916247​=0.29167 15 = 0.4666 \frac{7}{15}=0.4666157​=0.4666

然后我们把他们的取值按照recall是横坐标,precision是纵坐标画图如下:


其中A P = A 1 + A 2 + A 3 + A 4 AP = A1 + A2 +A3 +A4AP=A1+A2+A3+A4,具体计算如下:
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 = 0.2456095 = 24.56 % A1 = (0.0666-0)\times 1=0.0666 \\ A2 = (0.1333-0.0666)\times 0.6666 = 0.04446222 \\ A3 = (0.4-0.1333)\times 0.4285=0.11428095\\ A4 = (0.4666-0.4)\times0.3043=0.02026638 \\ AP = 0.0666+0.04446222+0.11428095+0.02026638=0.2456095=24.56\%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.02026638=0.2456095=24.56%

Mean Average Precision,mAP

mAP就是对每一个类别都计算出AP然后再计算AP平均值就好了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/114058
推荐阅读
相关标签
  

闽ICP备14008679号