Calibration of Neural Networks using Splines

Kartik Gupta, Amir Rahimi, Thalaiyasingam Ajanthan, Thomas Mensink, Cristian Sminchisescu, Richard Hartley

Introduction

Deep neural networks have achieved remarkable accuracy across various domains, yet they often suffer from poor calibration. A well-calibrated model's predicted probability should reflect the actual likelihood of the event occurring. However, modern architectures like ResNets tend to be overconfident, assigning high probabilities to incorrect predictions. This discrepancy can be critical in safety-sensitive applications such as autonomous driving or medical diagnosis, where a model's self-reported confidence must be trustworthy.

The Kolmogorov-Smirnov Calibration Error

Traditional calibration metrics, such as Expected Calibration Error (ECE), rely on partitioning predictions into discrete bins. This approach is inherently sensitive to the choice of binning strategy, which can lead to inconsistent error measurements depending on the number of bins or the placement of boundaries. To address this, the authors introduce a binning-free metric based on the Kolmogorov-Smirnov (KS) test.

The KS error is calculated by comparing the Cumulative Distribution Function (CDF) of the model's predicted scores against the cumulative sum of its actual accuracy. This provides a continuous and more robust measure of calibration that does not depend on arbitrary hyperparameters. As shown in Figure 1, an uncalibrated model exhibits a significant gap between predicted cumulative probability and actual cumulative accuracy.

Visualization of an uncalibrated model's output across four perspectives, including the cumulative KS-error plot (b) and the score-probability mapping (d).

Recalibration via Cubic Splines

To correct miscalibration, the paper proposes a post-hoc method using cubic splines. Unlike simpler methods like Temperature Scaling, which apply a single global parameter to scale logits, spline-based recalibration fits a flexible, smooth polynomial curve to the calibration data.

The process involves mapping the fractile of the scores to the empirical accuracy. Because splines are differentiable, an analytical mapping can be derived to transform the original, miscalibrated probabilities into well-calibrated ones. This method is "accuracy-preserving," as it modifies the confidence scores without altering the relative ranking of classes, ensuring the model's top-1 performance remains unchanged.

Experimental Results

The proposed method was evaluated on standard benchmarks including CIFAR-10, CIFAR-100, and ImageNet across various architectures like ResNet and DenseNet. The spline-based approach consistently outperformed Temperature Scaling, reducing calibration error to below 1% in most cases. For instance, on CIFAR-100 with a ResNet-110, the KS error dropped from a staggering 18.48% to just 0.57%. Figure 2 illustrates the effectiveness of the method, showing near-perfect alignment between predicted scores and empirical probabilities after calibration.

Post-calibration cumulative distribution plot showing the near-perfect alignment achieved by the spline method compared to the uncalibrated state.

Conclusion

By moving away from binning-based metrics and adopting flexible spline functions for recalibration, this work provides a more reliable and effective framework for ensuring neural network reliability. The method's ability to handle "top-r" calibration further extends its utility to complex multi-class scenarios where the confidence of secondary predictions is also vital for downstream decision-making.

Summary updated

BibTeX
@inproceedings{gupta2021calibration,
  author = {Kartik Gupta and Amir Rahimi and Thalaiyasingam Ajanthan and Thomas Mensink and Cristian Sminchisescu and Richard Hartley},
  title = {{Calibration of Neural Networks using Splines}},
  booktitle = {International Conference on Learning Representations},
  year = {2021},
  url = {https://openreview.net/forum?id=gPYensOGUO},
}
Figure