NEW
A classification loss that down-weights easy examples, focusing learning on hard, misclassified cases to address class imbalance.
DESCRIPTION
Focal Loss modifies cross-entropy by adding a modulating factor that reduces loss for well-classified examples, concentrating gradients on hard ones. Introduced with RetinaNet for dense object detection, it improves performance under extreme class imbalance. It’s widely used in detection and segmentation tasks. Hyperparameters (gamma, alpha) control focusing and class weighting, requiring careful tuning.
ALTERNATIVE DEFINITIONS
Lin et al., 2017 (arXiv)
We propose Focal Loss to address the class imbalance problem encountered during one-stage object detector training. The Focal Loss is designed to decrease the loss contribution from easy examples and extend the range in which an example receives low loss.
Original paper emphasizes one-stage detectors and imbalance mitigation.
TensorFlow Addons
Focal loss is a loss function that down-weights well-classified examples so that the classifier focuses more on hard, misclassified examples.
Concise API definition for sigmoid focal cross-entropy.
PyTorch
Computes the sigmoid focal loss between input logits and targets. Focal loss helps address class imbalance by penalizing hard-to-classify examples more.
Implementation-oriented description within PyTorch Vision.
RELATED TERMS
Cross-Entropy Loss Class Imbalance Object Detection RetinaNet Hard Example Mining Weighted Loss Logit Softmax Intersection over Union Data Augmentation
COMPETING TERMS
Weighted Cross-Entropy Online Hard Example Mining
KNOWLEDGE AREAS
TARGET AUDIENCE
AI Engineer Data Scientist MLOps Engineer Software Developer
EXTERNAL SOURCES
- arXiv - Original Focal Loss paper
- Keras - Keras CV focal loss API
- PyTorch - PyTorch focal loss function
TOP QUESTIONS
What is Focal Loss?
A loss function that reduces attention on easy examples and emphasizes hard, misclassified examples to counter class imbalance.
Category: Definition
Where did Focal Loss originate?
It was introduced by Lin et al. in the RetinaNet paper to improve one-stage object detectors under heavy class imbalance.
Category: Origin
Which tasks benefit from Focal Loss?
Dense object detection, instance segmentation, and other imbalanced classification tasks benefit from its focusing behavior.
Category: Example
How do gamma and alpha affect Focal Loss?
Gamma controls focusing on hard samples; alpha balances classes. Tuning both is key to performance.
Category: Requirements
What’s the difference between Focal Loss and weighted cross-entropy?
Weighted cross-entropy applies static class weights, while focal loss dynamically reduces loss for well-classified examples.
Category: Distinction
Is Focal Loss always better for imbalance?
Not always. Evaluate against alternatives like weighted losses and resampling; choose based on validation metrics.
Category: Opinion
What are common mistakes with Focal Loss?
Using extreme gamma values, ignoring calibration, and forgetting to tune alpha can degrade results.
Category: Mistakes
Does Focal Loss affect probability calibration?
Yes, it can impact calibration. Post-hoc calibration methods may be needed for well-calibrated probabilities.
Category: Risk
How to implement Focal Loss efficiently?
Use library implementations (TensorFlow Addons, PyTorch Vision) and vectorized operations to avoid numerical instability.
Category: HowTo