1. 程式人生 > >Focal Loss論文閱讀筆記

Focal Loss論文閱讀筆記

Focal Loss for Dense Object Detection

引入問題

目前目標檢測的框架一般分為兩種:基於候選區域的two-stage的檢測框架(比如fast r-cnn系列),基於迴歸的one-stage的檢測框架(yolo,ssd這種),two-stage的效果好,one-stage的快但是效果差一些。

本文作者希望弄明白為什麼one-stage的檢測器準確率不高的問題,作者給出的解釋是由於前正負樣本不均衡的問題(感覺理解成簡單-難分樣本不均衡比較好)

We discover that the extreme foreground-background class imbalance encountered during training of dense detectors is the central cause

樣本的類別不均衡會帶來什麼問題

(1) training is inefficient as most locations are easy negatives that contribute no useful learning signal; 
(2) en masse,the easy negatives can overwhelm training and lead to degenerate models.

由於大多數都是簡單易分的負樣本(屬於背景的樣本),使得訓練過程不能充分學習到屬於那些有類別樣本的資訊;其次簡單易分的負樣本太多,可能掩蓋了其他有類別樣本的作用(這些簡單易分的負樣本仍產生一定幅度的loss,見下圖藍色曲線,數量多會對loss起主要貢獻作用,因此就主導了梯度的更新方向,掩蓋了重要的資訊)


這裡寫圖片描述

對於two-stage的檢測器而言,通常分為兩個步驟,第一個步驟即產生合適的候選區域,而這些候選區域經過篩選,一般控制一個比例(比如正負樣本1:3),另外還通過hard negatiive mining(OHEM),控制難分樣本佔據的比例,以解決樣本類別不均衡的問題。 
對於one-stage的檢測器來說,儘管可以採用同樣的策略(OHEM)控制正負樣本,但是還是有缺陷,文中的說法是:

Like the focal loss,OHEM puts more emphasis on misclassified examples, but unlike FL, OHEM completely discards easy examples 
While similar sampling heuristics may also be applied, they are inefficient as the training procedure is still dominated by easily classified background examples

OHEM這篇論文還沒看,所以不是特別理解。 
所以作者提出Focal loss,基於損失函式做出改進。

解決方案:Focal Loss

作者提出一種新的損失函式,思路是希望那些hard examples對損失的貢獻變大,使網路更傾向於從這些樣本上學習。

作者以二分類為例進行說明: 
首先是我們常使用的交叉熵損失函式: 


這裡寫圖片描述
這裡寫圖片描述

要對類別不均衡問題對loss的貢獻進行一個控制,即加上一個控制權重即可,最初作者的想法即如下這樣,對於屬於少數類別的樣本,增大α即可 


這裡寫圖片描述

但這樣有一個問題,它僅僅解決了正負樣本之間的平衡問題,並沒有區分易分/難分樣本,按作者的話說:

Easily classified negatives comprise the majority of the loss and dominate the gradient. 
While α balances the importance of positive/negative examples, it does not differentiate between easy/hard examples.

因此後面有瞭如下的形式: 


這裡寫圖片描述

顯然,樣本越易分,pt越大,則貢獻的loss就越小,相對來說,難分樣本所佔的比重就會變大,見如下原文中的一個例子:

For instance, with γ = 2, an example classified with pt = 0:9 would have 100× lower loss compared with CE and with pt ≈ 0:968 it would have 1000× lower loss. This in turn increases the importance of correcting misclassified examples (whose loss is scaled down by at most 4× for pt ≤ .5 and γ = 2)

因此,通過這個公式區分了易分/難分樣本,在實際中,作者採用如下公式,即綜合了上述兩個公式的形式: 


這裡寫圖片描述

這裡的兩個引數α和γ協調來控制,本文作者採用α=0.25,γ=2效果最好

另外:作者提到了類別不均衡和模型的初始化問題,即數量很多的某一類樣本會起主導作用,在開始訓練的時候可能導致不穩定,作者提出的解決方法是:

To counter this, we introduce the concept of a ‘prior’ for the value of p estimated by the model for the rare class (foreground) at the start of training. 
For the final conv 
layer of the classification subnet, we set the bias initialization to b = − log((1 − π)=π), where π specifies that at the start of training every anchor should be labeled as foreground with confidence of ∼π.

π採用的是0.01,不太清楚為什麼要這麼做,留個問號,help

實驗框架

本文作者實驗時設計了一個叫RetinaNet的one-satge的網路結構,以證明通過Focal Loss,one-stage的網路結構也能夠達到two-stage的準確率,實際上採用的是基於resnet的FPN(特徵金字塔網路,可自行查閱論文論文連結),網路框架如下: 


這裡寫圖片描述

實驗結果

最好能在coco test-dev上達到 39.1AP,5Fps 


這裡寫圖片描述

由上圖可見,準確率高於two-stage的方法,並且速度可以得到保持


這裡寫圖片描述

上圖是各指標的對比實驗結果,具體可檢視論文 


這裡寫圖片描述

上圖表明瞭該loss對負樣本的影響很明顯,使得負樣本的loss集中在少數的樣本上:

As can be seen, FL can effectively discount the effect of easy negatives, focusing all attention on the hard negative examples.

另外Focal loss的形式並不一定要是公式那樣的形式,只要能夠發揮相同的作用即可,作者有實驗證明,具體可查閱論文。

結論

本文從loss的角度闡述了one-stage檢測器準確率低的問題,並給出瞭解決方案,很精彩。

參考

部落格:參考部落格 
論文:論文原文