Skip to main content
QUICK REVIEW

[Paper Review] Calibrating Deep Neural Networks using Focal Loss

Jishnu Mukhoti, Viveka Kulharia|arXiv (Cornell University)|Feb 21, 2020
Adversarial Robustness in Machine LearningComputer Science39 references87 citations
TL;DR

The paper shows that training with focal loss yields better-calibrated deep neural networks than cross-entropy, and that combining focal loss with temperature scaling achieves state-of-the-art calibration without sacrificing accuracy. It also provides a per-sample gamma selection strategy to automate calibration.

ABSTRACT

Miscalibration - a mismatch between a model's confidence and its correctness - of Deep Neural Networks (DNNs) makes their predictions hard to rely on. Ideally, we want networks to be accurate, calibrated and confident. We show that, as opposed to the standard cross-entropy loss, focal loss [Lin et. al., 2017] allows us to learn models that are already very well calibrated. When combined with temperature scaling, whilst preserving accuracy, it yields state-of-the-art calibrated models. We provide a thorough analysis of the factors causing miscalibration, and use the insights we glean from this to justify the empirically excellent performance of focal loss. To facilitate the use of focal loss in practice, we also provide a principled approach to automatically select the hyperparameter involved in the loss function. We perform extensive experiments on a variety of computer vision and NLP datasets, and with a wide variety of network architectures, and show that our approach achieves state-of-the-art calibration without compromising on accuracy in almost all cases. Code is available at https://github.com/torrvision/focal_calibration.

Motivation & Objective

  • Investigate miscalibration in high-capacity DNNs and its link to NLL overfitting under cross-entropy.
  • Propose and analyze focal loss as a calibration-improving training objective.
  • Develop a principled method to automatically select the focal loss hyperparameter gamma on a per-sample basis.
  • Assess calibration performance across diverse datasets and architectures, and compare with existing calibration methods.

Proposed method

  • Replace cross-entropy with focal loss during training to increase entropy of the predicted distribution and reduce overconfidence.
  • Derive and leverage an upper bound linking focal loss to regularised KL divergence to justify implicit entropy regularisation.
  • Introduce a per-sample gamma selection policy based on the ground-truth probability or each sample to control gradient magnitudes via a gamma schedule.
  • Empirically evaluate calibration (ECE, AdaECE, Classwise-ECE) and accuracy across CV and NLP datasets, with and without temperature scaling; compare against MMCE, Brier loss, and label smoothing.
  • Analyse gradient dynamics and implicit weight regularisation of focal loss, including theoretical propositions relating gamma, p (predicted probability), and gradient norms.

Experimental results

Research questions

  • RQ1Does focal loss improve model calibration relative to cross-entropy across diverse datasets and architectures?
  • RQ2How does focal loss affect overfitting to NLL and the confidence of incorrect predictions during training?
  • RQ3Can a per-sample gamma schedule automatically yield better calibration without extra validation tuning?
  • RQ4What is the impact of focal loss on out-of-distribution detection and robustness to distribution shift, compared to temperature scaling alone?

Key findings

  • Focal loss yields better calibration than cross-entropy, MMCE, Brier loss, and label smoothing in extensive experiments on vision and NLP tasks.
  • When combined with temperature scaling, focal-loss-trained models achieve state-of-the-art calibration while preserving accuracy.
  • A per-sample gamma policy (higher gamma for low ground-truth probabilities and lower gamma otherwise) improves calibration without extra validation.
  • Focal loss exhibits implicit regularisation: it moderates gradient magnitudes for overconfident predictions and reduces miscalibration associated with peakier distributions on misclassified samples.
  • Models trained with focal loss show superior out-of-distribution detection (higher AUROC on OoD tasks) and robust calibration under distribution shift, sometimes outperforming temperature scaling alone.
  • The paper provides practical guidance and theoretical insight into selecting gamma via a closed-form relation involving the Lambert W function, enabling per-sample gamma choices.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.