“SECTION 3Focal Loss The Focal Loss is designed to address the one-stage object…
- User
“SECTION 3Focal Loss The Focal Loss is designed to address the one-stage object detection scenario in which there is an extreme imbalance between foreground and background classes during training (e.g., 1:1000). We introduce the focal loss starting from the cross entropy (CE) loss for binary classification1: CE(p,y)={−log§−log(1−p)if y=1otherwise.(1) View SourceRight-click on figure for MathML and additional features.In the above y∈{±1} specifies the ground-truth class and p∈[0,1] is the model’s estimated probability for the class with label y=1. For notational convenience, we define pt: pt={p1−pif y=1otherwise,(2) View SourceRight-click on figure for MathML and additional features.and rewrite CE(p,y)=CE(pt)=−log(pt).
The CE loss can be seen as the blue (top) curve in Fig. 1. One notable property of this loss, which can be easily seen in its plot, is that even examples that are easily classified (pt≫.5) incur a loss with non-trivial magnitude. When summed over a large number of easy examples, these small loss values can overwhelm the rare class.
3.1 Balanced Cross Entropy A common method for addressing class imbalance is to introduce a weighting factor α∈[0,1] for class 1 and 1−α for class −1. In practice α may be set by inverse class frequency or treated as a hyperparameter to set by cross validation. For notational convenience, we define αt analogously to how we defined pt. We write the α-balanced CE loss as: CE(pt)=−αtlog(pt).(3) View SourceRight-click on figure for MathML and additional features.This loss is a simple extension to CE that we consider as an experimental baseline for our proposed focal loss.
3.2 Focal Loss Definition As our experiments will show, the large class imbalance encountered during training of dense detectors overwhelms the cross entropy 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. Instead, we propose to reshape the loss function to down-weight easy examples and thus focus training on hard negatives.
More formally, we propose to add a modulating factor (1−pt)γ to the cross entropy loss, with tunable focusing parameter γ≥0. We define the focal loss as: FL(pt)=−(1−pt)γlog(pt).(4) View SourceRight-click on figure for MathML and additional features.The focal loss is visualized for several values of γ∈[0,5] in Fig. 1. We note two properties of the focal loss. (1) When an example is misclassified and pt is small, the modulating factor is near 1 and the loss is unaffected. As pt→1, the factor goes to 0 and the loss for well-classified examples is down-weighted. (2) The focusing parameter γ smoothly adjusts the rate at which easy examples are down-weighted. When γ=0, FL is equivalent to CE, and as γ is increased the effect of the modulating factor is likewise increased (we found γ=2 to work best in our experiments).
Intuitively, the modulating factor reduces the loss contribution from easy examples and extends the range in which an example receives low 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).
- Assistant