A Note on the Stability of the Focal Loss
Abstract
The Focal Loss is a widely deployed loss function that is used to train various types of deep learning models. It is a modification of the cross-entropy loss designed to mitigate the effect of class imbalance in dense object detection tasks. By downweighting the losses for easy, correctly classified samples, the method places more emphasis on harder, misclassified ones. As a result, gradient updates are not dominated by samples that the model already handles correctly. The downweighting of the loss is achieved by scaling the cross-entropy loss with a term that depends on a focusing parameter $\gamma$. In this paper, we highlight an unaddressed numerical instability of the Focal Loss that arises when this focusing parameter is set to a value between 0 and 1. We present the theoretical basis of this numerical instability, show that it can be detected in the computation of Focal Loss gradients, and demonstrate its effects across several classification and segmentation tasks. Additionally, we propose a straightforward modification to the original Focal Loss to ensure stability whenever these unstable focusing parameter values are used.
Cite
Text
van Leeuwen et al. "A Note on the Stability of the Focal Loss." Transactions on Machine Learning Research, 2025.Markdown
[van Leeuwen et al. "A Note on the Stability of the Focal Loss." Transactions on Machine Learning Research, 2025.](https://mlanthology.org/tmlr/2025/vanleeuwen2025tmlr-note/)BibTeX
@article{vanleeuwen2025tmlr-note,
title = {{A Note on the Stability of the Focal Loss}},
author = {van Leeuwen, Martijn P. and Haak, Koen V. and Saygili, Gorkem and Postma, Eric O. and Ong, L.L. Sharon},
journal = {Transactions on Machine Learning Research},
year = {2025},
url = {https://mlanthology.org/tmlr/2025/vanleeuwen2025tmlr-note/}
}