Abstract
Sharpness-Aware Minimization (SAM) has emerged as a powerful technique for improving the generalization of deep neural networks by identifying flatter regions in the loss landscape. This work establishes a formal link between loss surface flatness and model calibration, proving that SAM implicitly maximizes predictive entropy. We further introduce Calibrated SAM (CSAM), a variant that specifically targets overconfident samples to minimize calibration error without compromising the generalization gains that made SAM famous.
Introduction
Modern deep neural networks often suffer from a "confidence problem." While they achieve state-of-the-art accuracy, they are frequently poorly calibrated—meaning they may assign a 99% probability to a prediction that is incorrect. In safety-critical domains like autonomous driving or medical diagnosis, such overconfidence can be catastrophic. While researchers have long observed that "flatter" solutions generalize better, the theoretical link between flatness and calibration has remained elusive until now.
Theoretical Framework: SAM as an Entropy Maximizer
The core contribution of this research is the mathematical proof that SAM's two-step optimization process—finding a worst-case perturbation and then updating weights—acts as an implicit regularizer. Specifically, SAM behaves similarly to Focal Loss, penalizing the negative entropy of the model's predictions. By avoiding "sharp" minima, the model naturally avoids the "spiky" probability distributions associated with overconfidence.
As illustrated in the figure above, the weighting factor $\lambda$ increases sharply as the model's confidence $\tilde{\mathbf{p}}_y$ approaches 1.0. This effect is amplified by the perturbation radius $\rho$. This mechanism forces the model to maintain higher predictive entropy, effectively preventing it from putting all its "probability eggs" in one basket.
Calibrated SAM (CSAM)
Building on this theoretical foundation, the authors propose CSAM. While standard SAM treats all training examples equally, CSAM introduces a hyperparameter ($\gamma$) that specifically suppresses the influence of overconfident examples during the optimization's outer loop. This forces the optimizer to focus even more on smoothing out the predictions of the most certain (and likely overconfident) samples.
Experimental Results
The authors validated their findings across standard benchmarks (CIFAR-10/100, ImageNet-1K) and robustness suites (CIFAR-C, ImageNet-C) using architectures ranging from ResNets to Vision Transformers (ViTs).
Key Findings
- Superior Calibration: On CIFAR-100, SAM achieved an Expected Calibration Error (ECE) of 2.11%, compared to 3.95% for standard SGD. CSAM further reduced this to 1.93%.
- ViT Performance: Vision Transformers, which are notoriously difficult to calibrate, saw massive improvements. For a ViT-S/16 on ImageNet, SAM dropped calibration error from 9.72% to 1.76% while simultaneously boosting top-1 accuracy by over 4%.
- Robustness to Distribution Shift: SAM-trained models maintain their calibration significantly better than SGD when faced with synthetic corruptions or out-of-distribution data.
The reliability diagrams above demonstrate the stark difference in calibration. While SGD produces a massive peak of examples with near 100% confidence despite lower accuracy (leading to a large "Gap"), SAM's confidence distribution is more aligned with its actual performance, resulting in a much smaller calibration gap.
Conclusion and Future Work
This research reveals that SAM is a "secret weapon" for model calibration. By proving the link between sharpness and entropy, the authors provide a principled way to build models that are not only accurate but also "honest" about their certainty. Future work will explore how SAM interacts with non-cross-entropy loss functions and seek more computationally efficient implementations of the CSAM algorithm.
Summary updated