Focal Loss and class imbalance in detectors
handling extreme class imbalance.
focal loss multiplies cross-entropy by a (1-p)^gamma factor that down-weights easy, well-classified examples so the vast easy background does not swamp the loss.
WHAT THIS TESTS Whether you understand the specific pathology of dense detectors and the precise mathematical fix, not just that focal loss helps imbalance.
A GOOD ANSWER COVERS One-stage detectors like RetinaNet densely predict over a huge grid of anchor boxes, on the order of one hundred thousand per image, of which only a handful contain objects. The overwhelming majority are easy background negatives the model already classifies confidently. With standard cross-entropy, each easy negative contributes a small but nonzero loss, and there are so many that their sum overwhelms the gradient from the rare hard foreground examples, so the model trains poorly. Focal loss modifies cross-entropy by multiplying it by a modulating factor of one minus p sub t raised to the power gamma, where p sub t is the model's probability for the true class. When an example is well classified, p sub t is near one, so the factor is near zero and its loss is suppressed; hard, misclassified examples keep nearly their full loss. Gamma, typically two, controls how aggressively easy examples are down-weighted, and an alpha factor adds a fixed class balance on top.
COMMON WRONG ANSWERS Saying it just reweights classes; alpha does that, but the key novelty is down-weighting by difficulty via gamma. Claiming it discards easy examples; it scales them down smoothly. Confusing it with hard negative mining, which selects a subset rather than reshaping every term's weight.
LIKELY FOLLOW-UPS What does gamma equals zero reduce to. How does focal loss differ from hard negative mining and OHEM. Why does this let a one-stage detector rival two-stage accuracy. What role does alpha play.
ONE CONCRETE EXAMPLE Suppose an easy background anchor has p sub t equal to zero point nine nine. Cross-entropy gives a small loss, but multiply it by one minus zero point nine nine, all squared with gamma two, which is about zero point zero zero zero one, nearly eliminating its contribution. A hard foreground anchor at p sub t zero point three keeps a factor of zero point seven squared, about zero point four nine, retaining most of its loss. Summed over a hundred thousand anchors, the easy background no longer drowns out the few hard objects, which is what let RetinaNet match two-stage detector accuracy.
Read the original → arxiv.org
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.