Introduction
Modern deep learning models often suffer from overconfidence, providing miscalibrated predictions where high confidence does not necessarily correlate with accuracy. This lack of reliable uncertainty estimation is a significant barrier to deploying AI in safety-critical domains like healthcare or autonomous driving. While Bayesian Deep Learning (BDL) offers a theoretical framework to address this by treating weights as probability distributions, traditional methods like Hamiltonian Monte Carlo or Variational Inference often struggle with scalability or fail to capture the complex geometry of the loss surface in high-dimensional neural networks.
This paper introduces SWAG (SWA-Gaussian), a simple, scalable, and effective baseline for uncertainty estimation. SWAG fits a Gaussian distribution to the trajectory of Stochastic Gradient Descent (SGD) iterates, providing a robust Bayesian approximation that scales to ImageNet-sized models and often outperforms more complex techniques.
Methodology: SWA-Gaussian (SWAG)
SWAG builds upon Stochastic Weight Averaging (SWA), which improves generalization by averaging weights during the final stages of training. SWAG extends this by capturing the fluctuations of the weights to define a posterior distribution.
The algorithm proceeds in two main phases:
- Training (Moments Estimation): During the final stages of training with a constant learning rate, the algorithm tracks the first moment (mean weights $\bar{\theta}$) and the second moment (diagonal covariance $\Sigma_{diag}$). Additionally, it maintains a low-rank deviation matrix $\hat{D}$ to capture the covariance between parameters.
- Inference (Bayesian Model Averaging): At test time, multiple weight sets $\tilde{\theta}_i$ are sampled from the approximate posterior $\mathcal{N}(\bar{\theta}, \frac{1}{2}\Sigma_{diag} + \frac{\hat{D}\hat{D}^\top}{2(K-1)})$. Predictions are generated by averaging the outputs of these sampled models.
Experimental Setup
The authors evaluated SWAG across a wide range of benchmarks to test its versatility and scalability:
- Computer Vision: CIFAR-10/100 and ImageNet using VGG, PreResNet, WideResNet, and DenseNet architectures.
- Transfer Learning: Training on CIFAR-10 and evaluating on STL-10.
- Language Modeling: LSTMs on Penn Treebank and WikiText-2.
- Regression: Standard UCI regression datasets.
- Out-of-Distribution (OOD): Detecting unseen classes to evaluate uncertainty robustness.
Key Results and Insights
The core insight of SWAG is that the SGD trajectory at the end of training effectively explores the local shape of the posterior distribution. By capturing this geometry, SWAG aligns its variance with the "flat" directions of the loss surface, leading to better-calibrated predictions.
Key findings include:
- Superior Calibration: SWAG consistently achieves lower Negative Log-Likelihood (NLL) and better Expected Calibration Error (ECE) than popular alternatives like MC Dropout or Temperature Scaling.
- Robustness to Distribution Shift: In transfer learning tasks, SWAG significantly outperformed Temperature Scaling, which typically fails when test data deviates from the training distribution.
- Scalability: SWAG was successfully applied to large-scale models like ResNet-152 on ImageNet, demonstrating its practical utility for modern deep learning.
- OOD Detection: SWAG proved more effective at assigning high entropy to out-of-distribution data compared to standard point-estimate models.
Limitations
Despite its strengths, SWAG has some limitations. It only estimates variance along the directions explored by the SGD optimizer, potentially underestimating uncertainty in other regions of the weight space. Additionally, the inference process is computationally more expensive than a single model due to the need for multiple samples and re-calculating Batch Normalization statistics for each sample. Finally, the scale of uncertainty is sensitive to the choice of the learning rate during the averaging phase.
Conclusion
SWAG provides a powerful and easy-to-implement baseline for Bayesian uncertainty. By leveraging the existing SGD training process, it offers a scalable solution that bridges the gap between standard deep learning and robust Bayesian inference.
Summary updated