EasyDeepLearn

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

hard

Answer

  • Focal loss = -(1    pt)γ    log(pt)(1\; - \;p_{t})\gamma\; \cdot \;\operatorname{log}(p_{t}), a modification of cross-entropy that adds a modulating factor (1    pt)γ(1\; - \;p_{t})\gamma.
  • When ptp_{t} is high (easy example), the loss is heavily down-weighted; when ptp_{t} is low (hard example), the modulator is close to 1 — focus on hard examples. γ  =  0\gamma\; = \;0 recovers cross-entropy; γ  =  2\gamma\; = \;2 is the standard for RetinaNet.
  • Combined with alpha per class, it addresses both easy-example overwhelm and class imbalance in the same objective — dominant loss in dense object detection.
Check yourself — multiple choice
  • Focal loss is a scaled MSE
  • Cross-entropy multiplied by (1    pt)(1\; - \;p_{t})^γ — down-weights easy examples, focuses on hard ones
  • Same as class weights
  • Only works for regression

Focal loss  =  (1    pt)\mathrm{loss}\; = \;(1\; - \;p_{t})^γ · CE — hard-example focus for imbalanced dense prediction.

#imbalance

Practise Supervised Learning

215 interview questions in this topic.

Related questions