【RetinaNet】Focal Loss for Dense Object Detection

Focal loss是Kaiming He和RBG发表在ICCV2017上的文章。

abstract:

one-stage网络和two-stage网络相比,one-stage会得到大量目标位置。one stage不好的原因在于:

  • 极度不平衡的正负样本比例:abchor近似于sliding window的方式会使正负样本接近1000:1,而且绝大部分的负样本都是easy example,这样就导致了下面这个问题:
  • gradient 被easy example dominant的问题:往往这些easy example 虽然loss很低,但是由于数量众多,对于loss依然有很大的贡献,从而导致了收敛到一个不够好的结果。

所以,作者的解决思想很直接:直接按照loss decay掉那些easy example的权重,这样使训练更加bias到有意义的样本中去。[摘自知乎]

 

在RCNN二阶段系列,class imbalance is addressed by a two-stage cascade and simpling heuristics[二阶段级联和采样启发式]。可以使用selective search、EdgeBoxes、DeepMask、RPN来进行预采样。这样可以快速的减少候选目标位置样本,过滤掉大部分的background samplings。在第二阶段就可以可以采用一个固定的foreground-to-background ratio(1:3)或者是online hard example mining(OHEM),为了保证在头部训练的时候有一个正负样本可控的平衡。

相反,在one-stage网络中,就要处理大量的候选目标定位。传统的方法可以使用bootstrapping or hard example mining的方法去解决。

paper method:

paper提出了一个新的loss函数来代替以往的方法去解决class imbalance的问题。The loss function is a dynamically scaled cross entropy loss, where the scaling fator decays to zero as confidence in the correct class increases。[作者还强调,focal loss的形式并不重要,主要是这样的思想。并且作者在论文的最后还尝试了其他的一些form实现]

                            

作者为了验证Focal loss的作用,设计了RetinaNet网络[最好效果是Resnet-101-FPN backbone, achieves a COCO test-dev AP of 39.1 while running at 5 fps]。

Focal loss:

训练的时候,不平衡的情况甚至可以达到foreground:background=1:1000,这样的训练样本对loss的产生是有不平衡问题的。所以introduce the focal loss starting from the cross entropy(CE) loss for binary classification。

                                                  

即当y为只有0和1值时(这里是因为在cornerNet里有y不全为0或1的情况所表述),CE(p, y)=-ylog(p)-(1-y)log(1-p)。但是论文中是y\in{-1,  1},p\in [0, 1] 。

  • Balanced Cross Entropy:now, a common methon for addressing class imbalance is to introduce a weighting factor \alpha \in [0, 1] for class 1 and 1-\alpha for class -1. In practice \alpha may be set by inverse class frequency or treated as a hyperparameter to set by cross validation.

                                                              

  • Focal Loss Definition:给cross entropy loss添加一个因子(1-P_t)^\gamma with tunable focusing parameter \gamma \ge 0,定义Focal loss函数如下,以及不同\gamma值的对比图[实验发现当\gamma=2时效果是最好的],实际上paper会再添加一个平衡超参\alpha_t这里有一个细节,实验采用sigmoid激活函数来产生p值,会相对softmax产生一个更好的效果

                                                 

                                                 

                                                 

  • Class Imbalance and Two-stage Detectors:二阶段的检测器经常会使用到cross entropy loss,但是不会使用\alpha-balancing or Focal loss,他们主要通过两种机制来解决类别不平衡问题:(1)a two-stage cascade(2)biased minibatch sampling。首先在第一阶段,会通过选取候选框减少一大部分的样本,然后在第二阶段训练的时候,即训练head的时候,通过biased sampling来取样,a 1:3 ratio of positive to negative example。This ratio is like an implicit \alpha-balancing factor that is implemented via sampling. 论文所提出的Focal loss方法就是为了在one-stage detector实现这些机制。

RetinaNet detector

由一个backbone和两个task-specific子网络组成,backbone用来计算feature map。

  • Feature Pyramid Network backbone:构建一个levels为p_3-p_7的金字塔,所有的level的channel为256。
  • Anchor:use translation-invariant anchor boxes similar to those in the RPN variant in  "Feature pyramid networks for object detection"。在金字塔的p_3p_7,分别有32^2512^2规格的anchors感受区域[The anchors have areas of 32^2 to 512^2 on pyramid levels p_3 to p_7]。在金字塔每一层,使用ratios{1:2, 1:1, 2:1},同时增加anchors of sizes{2^0,2^{1/3}, 2^{2/3}} of the original set of 3 aspect ratio anchors,那么每一层就有9中anchors,结合所有的感受区域[相同的anchor在不同level有不同大小的感受区域],那么this anchors can cover the scale range 32-813pixels with the respect to the network's input image。                                         每个anchor都会产生一个K one-hot vector of classification targets,其中K是目标的类别数量,a 4-vector of box regression targets。这些anchor与gt的IoU阈值大于0.5认为是对应类别正样本即前景样本,在0到0.4之间则认为是background样本,0.4到0.5之间的ignored。每个anchor最多只被安排对应于一个object box,Box regression targets are computed as the offset between each anchor and its assigned object box, or omitted if there is no assignment. 

           

  • Classification Subnet:This subnet is a small FCN attached to  each FPN levels, parameters of this subnet are shared across all pyramid levels。设计是相当简单的:从一个给定的pyramid level取出有c通道的feature map,分类子网络([c个3x3conv+relu]x4+K*A个3x3conv+sigmoid/softmax,这里K是object classes, A anchors),paper中使用C=256,A=9。
  • Box Regression Subnet:regression the offset from each achor box to  a nearby ground-truth object。作者使用了class-agnostic bounding box regressor which uses fewer parameters and we found to be equally effective。

Inference and Training

  • Inference:为了提升速度,先将confidence<0.05的box-predictions去掉,然后box predictions对每一个FPN level仅仅是取1k top-scoring predictions。The top predictions  from all levels are merged and non-maximum suppression with a threshold of 0.5 is applied to yield the final detections。
  • Focal loss:发现\gamma=2会实验效果很好,RetinaNet在\gamma\in [0.5, 5]鲁棒性较高。When training RetinaNet, the focal loss is applied to all~100k anchors normalized by the number of anchors assigned to a ground-truth box(not total anchors, since the vast majority of anchors are easy negatives and receive negligible loss values under the focal loss) in each sampled image。
  • Initialization:for the final conv layer of the classification subnet,we set the bias initialization to b=-log((1-\pi)/\pi),其中\pi阐述了:训练每个anchor开始的时候,被标记为foreground with confidence of ~\pi,paper中使用\pi=0.01,这样的初始化可以在训练迭代第一次的时候防止大量background anchors产生大的loss值。

Experiments

                                                              

  • Focal loss VS. online hard example mining(OHEM):同focal loss一样,ohem会重视被误分类的例子,但是不像FL,OHEM会完全的放弃easy examples。[Specifically, in OHEM each example is scored by its loss, non-maximum suppression is then applied, and a minibatch is constructioned with the highest-loss examples.],最后minibatch取P:N=1:3。but FL is more effective than OHEM with a gap of 3.2AP。
  • Focal loss VS.Hinge loss:略,作者没有花功夫去优化比较。

 

Appedix:Focal Loss

附录部分是对Focal loss其他形式的一些阐述,因为作者说The exact form of the focal loss is not crucial。Focal loss的具体的形式不是最关键的,主要是这样的一种样本对loss贡献的权重思想。

We now show an alternate instantiation of the focal loss that has similar properties and yields conparable results。

                                            

 

 

    

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值