Object Detection

focal loss

Focal loss (Lin et al., 2017, the RetinaNet paper) is a modification of the standard cross-entropy classification loss designed to fix the extreme foreground-background imbalance that cripples dense one-stage detectors. The problem: a one-stage detector scores tens of thousands of anchors per image, but only a handful contain objects — the rest are 'easy' background. Even though each easy negative contributes a tiny loss, there are so many of them that their summed gradient drowns out the few hard, informative examples, and training stalls.

Focal loss attacks this by down-weighting easy examples so the model focuses on hard ones (hence 'focal'). Start from cross-entropy for the true class, CE = −log(p_t), where p_t is the predicted probability assigned to the correct class. Focal loss multiplies this by a modulating factor (1 − p_t)^γ: FL = −(1 − p_t)^γ · log(p_t). When an example is already classified confidently (p_t near 1), (1 − p_t)^γ is near 0, so its loss is suppressed; when it is misclassified (p_t small), the factor is near 1 and the full loss remains. The focusing parameter γ (commonly 2) controls how aggressively easy examples are discounted; an optional α balances the positive/negative classes.

The effect is that a flood of easy negatives, each now contributing almost nothing, can no longer overwhelm the gradient. With γ = 2, an example classified at p_t = 0.9 has its loss scaled by (0.1)² = 0.01 — a 100× reduction — while a hard example at p_t = 0.1 is scaled by (0.9)² ≈ 0.81, barely touched. This lets a one-stage detector train on the full dense set of anchors without the hard-negative-mining or 1:3 sampling tricks that SSD needed.

Focal loss was the missing piece that let one-stage detectors match two-stage accuracy: RetinaNet, a plain FPN-based dense detector trained with focal loss, beat the two-stage detectors of its day on COCO while remaining faster. The idea generalized far beyond detection to any task with heavy class imbalance, and remains a default tool for dense prediction.

Focal loss treats the symptom (imbalanced loss) within a fixed anchor set; it does not change which anchors are positive. Modern detectors often pair or replace it with better label assignment (ATSS, OTA) that changes which samples count as positive in the first place — the two ideas are complementary, not redundant.

Also called
FL