赞
踩
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%
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指正确检测出来的目标框数量占所有真实目标框数量的比例。
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曲线越靠近右上越好。
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无关。表格如下:
Image | Detections | Confidences | TP or FP |
---|---|---|---|
Image1 | A | 88% | FP |
Image1 | B | 70% | TP |
Image1 | C | 80% | FP |
Image2 | D | 71% | FP |
Image2 | E | 54% | TP |
Image2 | F | 74% | FP |
Image3 | G | 18% | TP |
Image3 | H | 67% | FP |
Image3 | I | 38% | FP |
Image3 | J | 91% | TP |
Image3 | K | 44% | FP |
Image4 | L | 35% | FP |
Image4 | M | 78% | FP |
Image4 | N | 45% | FP |
Image4 | O | 14% | FP |
Image5 | P | 62% | TP |
Image5 | Q | 44% | FP |
Image5 | R | 95% | TP |
Image5 | S | 23% | FP |
Image6 | T | 45% | FP |
Image6 | U | 84% | FP |
Image6 | V | 43% | FP |
Image7 | X | 48% | TP |
Image7 | Y | 95% | FP |
有了这些值,我们就开始按照Confidences大小排序来计算Precision和Recall值:
Image | Detections | Confidences | TP or FP | Precision | Recall |
---|---|---|---|---|---|
Image5 | R | 95% | TP | 1 1 = 1 \frac{1}{1}=111=1 | 1 15 = 0.0666 \frac{1}{15}=0.0666151=0.0666 |
Image7 | Y | 95% | FP | 1 2 = 0.5 \frac{1}{2}=0.521=0.5 | 1 15 = 0.0666 \frac{1}{15}=0.0666151=0.0666 |
Image3 | J | 91% | TP | 2 3 = 0.6666 \frac{2}{3}=0.666632=0.6666 | 2 15 = 0.1333 \frac{2}{15}=0.1333152=0.1333 |
Image1 | A | 88% | FP | 2 4 = 0.5 \frac{2}{4}=0.542=0.5 | 2 15 = 0.1333 \frac{2}{15}=0.1333152=0.1333 |
Image6 | U | 84% | FP | 2 5 = 0.4 \frac{2}{5}=0.452=0.4 | 2 15 = 0.1333 \frac{2}{15}=0.1333152=0.1333 |
Image1 | C | 80% | FP | 2 6 = 0.3333 \frac{2}{6}=0.333362=0.3333 | 2 15 = 0.1333 \frac{2}{15}=0.1333152=0.1333 |
Image4 | M | 78% | FP | 2 7 = 0.2857 \frac{2}{7}=0.285772=0.2857 | 2 15 = 0.1333 \frac{2}{15}=0.1333152=0.1333 |
Image2 | F | 74% | FP | 2 8 = 0.25 \frac{2}{8}=0.2582=0.25 | 2 15 = 0.1333 \frac{2}{15}=0.1333152=0.1333 |
Image2 | D | 71% | FP | 2 9 = 0.2222 \frac{2}{9}=0.222292=0.2222 | 2 15 = 0.1333 \frac{2}{15}=0.1333152=0.1333 |
Image1 | B | 70% | TP | 3 10 = 0.3 \frac{3}{10}=0.3103=0.3 | 3 15 = 0.2 \frac{3}{15}=0.2153=0.2 |
Image3 | H | 67% | FP | 3 11 = 0.2727 \frac{3}{11}=0.2727113=0.2727 | 3 15 = 0.2 \frac{3}{15}=0.2153=0.2 |
Image5 | P | 62% | TP | 4 12 = 0.3333 \frac{4}{12}=0.3333124=0.3333 | 4 15 = 0.2666 \frac{4}{15}=0.2666154=0.2666 |
Image2 | E | 54% | TP | 5 13 = 0.3846 \frac{5}{13}=0.3846135=0.3846 | 5 15 = 0.3333 \frac{5}{15}=0.3333155=0.3333 |
Image7 | X | 48% | TP | 6 14 = 0.4285 \frac{6}{14}=0.4285146=0.4285 | 6 15 = 0.4 \frac{6}{15}=0.4156=0.4 |
Image4 | N | 45% | FP | 6 15 = 0.45 \frac{6}{15}=0.45156=0.45 | 6 15 = 0.4 \frac{6}{15}=0.4156=0.4 |
Image6 | T | 45% | FP | 6 16 = 0.375 \frac{6}{16}=0.375166=0.375 | 6 15 = 0.4 \frac{6}{15}=0.4156=0.4 |
Image3 | K | 44% | FP | 6 17 = 0.3529 \frac{6}{17}=0.3529176=0.3529 | 6 15 = 0.4 \frac{6}{15}=0.4156=0.4 |
Image5 | Q | 44% | FP | 6 18 = 0.3333 \frac{6}{18}=0.3333186=0.3333 | 6 15 = 0.4 \frac{6}{15}=0.4156=0.4 |
Image6 | V | 43% | FP | 6 19 = 0.3157 \frac{6}{19}=0.3157196=0.3157 | 6 15 = 0.4 \frac{6}{15}=0.4156=0.4 |
Image3 | I | 38% | FP | 6 20 = 0.3 \frac{6}{20}=0.3206=0.3 | 6 15 = 0.4 \frac{6}{15}=0.4156=0.4 |
Image4 | L | 35% | FP | 6 21 = 0.2857 \frac{6}{21}=0.2857216=0.2857 | 6 15 = 0.4 \frac{6}{15}=0.4156=0.4 |
Image5 | S | 23% | FP | 6 22 = 0.2727 \frac{6}{22}=0.2727226=0.2727 | 6 15 = 0.4 \frac{6}{15}=0.4156=0.4 |
Image3 | G | 18% | TP | 7 23 = 0.3043 \frac{7}{23}=0.3043237=0.3043 | 7 15 = 0.4666 \frac{7}{15}=0.4666157=0.4666 |
Image4 | O | 14% | FP | 7 24 = 0.2916 \frac{7}{24}=0.2916247=0.2916 | 7 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%
mAP就是对每一个类别都计算出AP然后再计算AP平均值就好了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。