DL0046 Focal Loss

What is focal loss, and why does it help with class imbalance?

Answer

Focal loss augments cross-entropy with a modulating factor (1 - p_t)^\gamma that shrinks the loss of easy, well-classified examples toward zero, so the vast number of easy negatives in imbalanced data stops dominating the gradient. Training then concentrates on hard, misclassified, or minority-class examples, which is where the useful learning signal actually lives.

(1) Modulating Factor: (1 - p_t)^\gamma is near 0 when the model is confident and correct, and near 1 when it is wrong, so easy examples are automatically down-weighted.
(2) Class Imbalance Effect: In detection-style problems with ~100k easy negatives per positive, plain cross-entropy is swamped by their accumulated gradient; focal loss suppresses it.
(3) Optional Balancing: A per-class weight \alpha_t can additionally correct the base-rate skew of the classes themselves.

Mathematical Formulation:
\mathrm{FL}(p_t) = -\alpha_t\, (1 - p_t)^\gamma \log(p_t)

Where:

  • p_t is the model’s predicted probability for the ground-truth class.
  • \gamma \geq 0 is the focusing parameter: larger values suppress easy examples harder; \gamma = 0 with \alpha_t = 1 recovers plain cross-entropy.
  • \alpha_t \in (0,1) is an optional per-class balancing weight for class t.
Loss versus true-class probability curves for cross-entropy and focal loss at several gamma values, showing larger gamma suppressing the loss of confident correct predictions toward zero.

Figure 1: Focal loss curves for several \gamma: as \gamma grows, the loss of confident correct predictions (high p_t) collapses toward zero while hard examples keep full weight.

Scenariop_t (True-Class Prob)Factor (1-p_t)^\gammaEffect on Loss
Easy exampleHighLow → 0Down-weighted to near zero
Hard exampleLowHigh → 1Keeps full learning signal

Table 1: How the modulating factor behaves: easy examples fade out, hard examples dominate the gradient.

Typical Settings: The RetinaNet paper found \gamma = 2 with \alpha = 0.25 (for the positive class) works well; the useful range is usually \gamma \in [1, 3]; too large over-focuses on noisy or mislabeled outliers.


Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *