Focal Loss for Dense Object Detection (document reading)

table of Contents

motivation

Thinking

Innovation

Training and Testing


motivation

Although the two-stage detector is a success, then the question is: a simple single stage can achieve a similar accuracy it single-stage applied to the target position, and aspect ratio of conventional scale, intensive sampling?. Recent studies SSD on YOLO and other single phase showed promising results compared with the most advanced two-stage process, it can produce precision faster detector within 10-40%. This paper further expand in this area: the first time a single-stage target detector, and the most advanced COCO AP more complex two-stage detector matches. To achieve this result, the training process to determine the class imbalance is hindering the single phase detector to achieve a major obstacle to the most accurate, and proposes a new loss function to eliminate this obstacle.

Thinking

Class imbalance problem is solved by a two-stage cascade sampling and heuristics. Mentioned proposal stage (e.g. Selective Search algorithm, EdgeBoxes, DeepMask, RPN) to quickly reduce the number of candidates to a small number of positions, to filter out most of the background samples. In the second stage of classification, the heuristic performs sampling, such as a fixed front background ratio (1: 3) or a hard-line sample tap (OHEM) [31], can be managed to maintain the balance between the foreground and background.

In contrast, a single stage detector must handle a large number of candidate uniform sampling position in the image frame. In practice, this usually corresponds to enumerate about 100k positions, these positions densely covered space location, size and aspect ratio. Although you can use similar sampling heuristics, but the efficiency is very low, because the training process is still easily classified into class background. Such inefficiency is a classical problem in the object detection is usually solved by bootstrapping [33,29] or hard example mining [37,8,31] techniques.

In this paper, we propose a new loss function, it is more effective than the conventional method of processing class imbalance. Cross entropy loss function is a dynamic scaling loss, increased when the confidence of the correct type, the scale factor attenuation is zero, as shown in FIG.

                                          

Intuitively, this scaling factor may be reduced automatically in a simple example of the training process the weights, and to quickly focus on the model exemplary difficult. Experiments show that the power loss can be trained in a single stage with high precision detector, performance of the detector is significantly better than samples heuristic or hard exemplary excavation, before the most advanced training technique a single level detector. Finally, we note that the exact form of the focal length of the loss is not important, we also show other examples of Keyihuode similar results.

In order to demonstrate the effectiveness of the proposed loss of focus, we designed a simple single-stage target detector, called Retinanet, its name comes from the densely sampled input image in the target location. It is designed for efficient network features within an anchor box and the use of the pyramid. It draws on the latest from the point of view. RetinaNet efficient and accurate; our best model ResNet-101-FPN backbone, running at a speed of 5 fps case, realized COCO test-dev AP 39.1, single stage than the best previously published detecting unit Model results and two-stage detector, as shown below.

                                            

Innovation

Detailed derivation (1) Focal loss of

Focal loss is designed to solve the target detection phase of a scene, there is an extreme imbalance in the foreground and background classes in the training phase. From the start of cross-entropy binary lead Focal loss,

                                                   $$ CE=\left\{ \begin{aligned} -log(p)\ \ if \ y = 1 \\ -log(1-p) \ \ \ otherwise \end{aligned} \right. $$

In the above formulas y\in \{\pm 1\}specified tag class, and p\in[0,1]when the tag 1 y = estimated probability model class. For ease of labeling, the definition p_t:

                                                     $$ p_t=\left\{ \begin{aligned} p\ \ if \ y = 1 \\ 1-p \ \ \ otherwise \end{aligned} \right. $$

And rewriting CE(p,y)=CE(p_t) =-log(p_t).

CE blue curve is the figure above, the nature of such a noteworthy loss is even an example of the classification is readily also cause the loss of non-trivial, it is easily seen in the figures thereof (p_t\gg .5). When a large number of simple examples are summed, the value of these small losses may overwhelm a small class.

A common approach is to introduce class imbalance factor a \alpha \in[0,1]class 1 and 1-\alphaclass 1. In practice, α may be provided by cross-validation by setting the frequency of super class or inverse parameter considered. For ease of marking, the \alpha-balancedCE loss written as:

                                                                                    CE(p_t) = -\alpha_t log(p_t)

这个损失是CE损失的一个简单延伸,为我们提出的Focal loss考虑一个实验的baseline。

实验结果表明,在稠密探测器训练过程中所遇到的较大的类不平衡抵消了交叉熵损失。容易分类的负样本构成了大部分的损失,并主导梯度。而α平衡正面/负面例子的重要性,不区分容易/难的例子。相反,我们建议重塑损失函数,减少简单例子的权重,从而将训练重点放在困难的负面因素上。

更一般的,我们提出对交叉熵损失增加一个调制因子(1-p_t)^{\gamma },利用可调焦虑的参数\gamma \geqslant 0,将focal loss定义为:

                                                                  FL(p_t) = -(1-p_t)^{\gamma}log(p_t)

Focal loss可以用若干个值来表示\gamma \in [0,5],如最上图所示。注意Focal loss的两个性质:(1)当一个例子被误分类并且p_t比较小的时候,调制系数接近1并且损失无影响。因为p_t趋近于1,并且因子趋近于0,分类良好的示例的损失是向下加权的。(2)聚焦参数\gamma平滑的调整速度,在这种情况下,简单的例子就会被减权。当\gamma = 0时,FL相当于CE,当γ增加调制的影响因素是同样增加(在实验中发现\gamma=2是最佳的)。

直观地说,调制因子减少了来自简单示例的损失贡献,并扩展了示例接受低损失的范围。例如,使用\gamma =2p_t = 9时例子的分类相比于CE损失降低了100倍,p_t = 0.968时损失降低了1000倍。这反过来又增加了纠正错误分类示例的重要性,对p_t\leq .5\gamma = 2,损失最多降低了4倍。

在实际中使用Focal loss的\alpha -balance变体:

                                                            FL(p_t)=-\alpha_t(1-p_t)^\gamma log(p_t)

在实验中采用这种方法和非\alpha -balance相比精度有略微的提升。最后,我们注意到,损失层的实现结合了计算p的sigmoid操作和损失计算,使得数值更加稳定。

默认情况下,二值分类模型初始化为输出y = - 1或1的概率相等。在这样的初始化下,在类不平衡的情况下,由于类频率而造成的损失会主导全员损失,导致早期训练的不稳定。为了解决这一问题,在训练开始时引入了“先验”的概念,即稀有类(前景)的模型估计的p值。我们通过π表示先验,这样模型的估计p稀有类的例子很低,例如0.01。我们注意到这是模型初始化的一个变化(参见§4.1),而不是损失函数的变化。我们发现,在严重严重不平衡的情况下,这种方法可以提高交叉熵和焦点损失的训练稳定性。

两阶段检测器通常通常用交叉熵损失来训练不用\alpha-balance或Focal loss。相反,两阶段检测器通过两种机制来解决类不平衡问题:(1)两级联和(2)有偏的小批量抽样。第一个级联阶段是一个目标建议机制,它将几乎无限的可能目标位置集减少到1000或2000个。重要的是,所选择的建议不是随机的,而是可能与真实的对象位置相对应的,这消除了绝大多数容易产生的负面影响。在培训第二阶段时,偏置抽样通常用于构建包含正、负样本比例为1:3的minibatch。这个比例是一个隐式实现通过抽样\alpha-balance因素。我们提出的Focal loss是通过损失函数在一阶段检测器中直接解决这个问题。

(2)Retinanet

Retinanet是由一个主干网和两个特定于任务的子网组成的单一、统一的网络。主干负责计算整个输入图像上的卷积特征图,是一个自定义卷积网络。第一子网对骨干网的输出进行卷积对象分类;第二个子网络执行卷积边界盒回归。这两个子网具有一个简单的设计,我们特别针对单阶段密集检测提出了这个设计,如下图所示。虽然对于这些组件的细节有许多可能的选择,但是大多数设计参数对实验中显示的精确值并不特别敏感。接下来我们将描述Retinanet的各个组成部分。

                                   

FPN骨干网:采用特征金字塔网络(FPN)作为支持网络的骨干网络。简而言之,FPN通过自顶向下的路径和横向连接扩展了一个标准的卷积网络,使得该网络能够有效地从一个分辨率输入图像构建一个丰富的多尺度特征金字塔,如上图(a)-(b)所示。金字塔的每一层都可以用来探测不同尺度的物体。FPN改进了全卷积网络(FCN)的多尺度预测,这可以从RPN和深度掩码(DeepMask-style)方案以及两级检测器(Fast R-CNN或Mask R-CNN)的改进中看出。接下来,我们在ResNet架构的基础上构建FPN。构建了一个从P3级到P7级的金字塔,其中l表示金字塔级(P_l的分辨率比输入低2^l)。在所有金字塔级别有C = 256通道。金字塔的细节通常会有一些细微的差别。虽然很多设计选择并不重要,但我们强调使用FPN主干网是至关重要的;仅使用最后一层ResNet的特征进行的初步实验获得了较低的AP。 

Anchor:使用平移不变的锚框,类似于Fast R-CNN中的RPN变体。在P3 ~ P7层,锚点的面积分别为32^2\sim 512^2。就像Fast R-CNN中一样,在每个金字塔级别,使用三个纵横比(1:2,1:1,2:1)的锚。对于比Fast R-CNN更密集的尺度覆盖,在每一层我们都添加了原3个纵横比锚的尺寸{\{2^0,2^{1/3},2^{2/3}\}}的锚。这在我们的设置中改进了AP。每层总共有一个A=9个锚点,它们覆盖了32 -813像素范围内的网络输入图像。每个锚点都有一个长度为K的分类目标的一个hot向量,其中K为对象类的数量,一个box regression目标的4个向量。我们使用了来自RPN的赋值规则,但修改了多类检测和调整阈值。具体来说,锚点使用相交IoU阈值0.5分配到背景对象框;如果groundtruth个背景的IoU在[0,0.4]则被归为背景类。由于每个锚点最多分配给一个对象框,我们将其长度K label向量中的对应条目设置为1,所有其他条目设置为0。如果一个锚没有被分配,这可能发生在重叠的[0.4,0.5],它在训练期间被忽略。盒回归目标计算为每个锚点与其分配的对象盒之间的偏移量,如果没有分配,则省略。

分类子网络:分类子网为每个A锚和k对象类预测对象在每个空间位置出现的概率。这个子网是一个小的FCN附加到每个FPN级;此子网的参数在所有金字塔级别上共享。它的设计很简单。子网从一个给定的金字塔级获取一个带有C通道的输入特征图,应用4个3×3 conv层,每个层都有C个滤波器,每个滤波器后面都有ReLU激活,然后是一个带有K A滤波器的3×3 conv层。最后,sigmoid激活被附加到每个空间位置的KA二进制预测输出中,见上图 (c)。在大多数实验中使用C = 256和A = 9。与RPN相比,对象分类子网更深,只使用3×3 卷积层,并且不与box regression子网共享参数。我们发现这些高层次的设计决策比超参数的特定值更重要。

回归子网络:与对象分类子网并行,我们将另一个小FCN附加到每个金字塔级别,以便将每个锚框的偏移量回归到附近的ground-truth对象(如果存在的话)。盒子的设计回归子网与分类相同子网除了它终止在4线性输出/空间位置,如上图 (d)所示。对每个空间位置的A个锚,这四个输出预测锚和groundtruth框之间的相对偏移量(使用R-CNN的标准box参数)。我们注意到,与最近的工作不同,我们使用了一个类无关的边界框回归器,它使用较少的参数,并且我们发现同样有效。对象分类子网和箱形回归子网虽然具有相同的结构,但使用不同的参数。

训练和测试

推论:RetinaNet形成一个单一的FCN,由一个ResNet-FPN主干、一个分类子网和一个box regression子网组成,如上图所示。因此,推理只涉及通过网络前向传播图像。为了提高速度,我们在阈值检测器置信度为0.05后,只对每个FPN级别的最高1k得分预测进行解码。将各个级别的最高预测进行合并,并使用阈值为0.5的NMS来产生最终的检测结果。

Focal loss:我们使用本文介绍的焦损耗作为分类子网输出的损耗。§5中我们将展示,我们发现\gamma =2工作在实践和RetinaNet相对强劲的\gamma\in[0.5,5]。我们强调,当训练RetinaNet时,Focal loss应用于每个采样图像中的所有∼100k锚点。这与通常使用启发式抽样(RPN)或硬示例挖掘(OHEM, SSD)来为每个小批选择一组锚(例如,256)的做法形成了对比。图像的总Focal loss计算为所有∼100k锚点上的Focal loss之和,由分配给ground-truth框的锚点数量标准化。由于绝大多数锚都是易负性的,且在Focal loss下损失值可以忽略不计,所以我们用所分配的锚的个数而不是总锚的个数来进行归一化。最后我们注意\alpha,权重分配到罕见的类,也有一个稳定的范围内,但它与\gamma使得有必要选择这两个在一起(见表1 a和1 b)。一般\alpha应该稍微降低\gamma增加(\gamma=2\alpha=0.25的效果最好)。

初始化:使用ResNet-50-FPN和ResNet-101-FPN骨干进行实验。在ImageNet1k上对基础ResNet-50和ResNet-101模型进行预训练。使用原始的残差网络模型。对FPN添加的新层初始化方式和原始FPN一样。所有新conv层RetinaNet子网中除了最后一层用bias b= 0和\sigma =0.01的高斯权重进行初始化。分类子网络的最后一个卷积层,把bias初始化为b=-log((1-\pi)/\pi)\pi指定在开始训练的时候每个anchor被标记为\pi的置信度。在所有实验中使用\pi = . 01,虽然结果对精确值是鲁邦的。这种初始化可以防止大量的背景anchor在训练的第一次迭代中产生较大的、不稳定的损失值。

优化:用随机梯度下降法(SGD)训练Retinanet。在8个GPU上使用同步SGD,每个小批处理共有16个图像(每个GPU 2个图像)。除非另有说明,所有模型都经过90k迭代训练,初始学习率为0.01,然后在60k时除以10,在80k迭代时再除以10。除非另有说明,否则我们使用水平图像翻转作为唯一的数据增强形式。重量衰减为0.0001,动量为0.9。训练损失是box regression中焦距损失与标准光滑L1损失之和。

Guess you like

Origin blog.csdn.net/weixin_36670529/article/details/91041803
Recommended