Adversarial Training With Stochastic Weight Average

Joong-won Hwang, Youngwan Lee, Sungchan Oh, Yuseok Bae

TL;DR

Adversarial training is the gold standard for defending neural networks, but it suffers from severe overfitting and high computational costs. This paper introduces SWAAT, a method that averages model weights during the training process to achieve the benefits of an ensemble of models—higher robustness and better generalization—without the massive overhead of training multiple networks.

What Problem Does This Paper Address?

Deep Learning models are notoriously fragile; small, intentional perturbations to an input (adversarial attacks) can easily fool them. Adversarial Training (AT)—where you train the model on these "attack" images—is the most effective defense, but it has two major flaws:

  1. Overfitting: AT requires significantly more data than standard training to generalize well. Without it, the model "memorizes" specific attacks and fails on new ones.
  2. The Ensemble Dilemma: While combining multiple models (ensembling) usually reduces overfitting, doing so in AT creates a "Dilemma of Decoupling." If you generate attacks against individual models, the ensemble as a whole remains vulnerable. If you generate attacks against the whole ensemble, the individual models become weak and lose their diversity.

Methods

The authors propose SWAAT (Stochastic Weight Average based Adversarial Training). It builds on the concept of Stochastic Weight Averaging (SWA), which typically averages weights at the end of training to find a flatter, more generalizable region of the loss landscape.

Key innovations in SWAAT include:

  • Continuous Aggregation: Unlike standard SWA, SWAAT aggregates weight states after every iteration and updates the active model with this average at the end of every epoch.
  • Solving the Dilemma: Because the model is essentially an "ensemble in time," the adversarial examples generated during training are naturally coupled with the averaged model, avoiding the decoupling dilemma.
  • BN Statistic Recalculation: When weights are averaged, Batch Normalization (BN) statistics become mismatched. SWAAT recalculates these using natural images, which the authors surprisingly found to be as effective as using adversarial images.
  • Data Resampling for Diversity: To prevent the "temporal ensemble" from becoming too uniform, the authors use Hard Example Mining (HEM). They identify images the current model struggles with and increase their frequency in the next training epoch.

Datasets

The authors evaluated SWAAT on three standard computer vision benchmarks:

  • CIFAR-10: 10-class object recognition.
  • CIFAR-100: 100-class object recognition.
  • SVHN: Street View House Numbers.

They used Pre-activation ResNet18 and WideResNet-28-10 architectures for their experiments.

Key Insights and Ideas

  • The "Dilemma of Decoupling": This is a crucial conceptual contribution. It explains why naive ensembles often fail in adversarial settings: you can't easily optimize an attack that is "strong enough" for both the parts and the whole simultaneously.
  • Flatter Minima = Better Robustness: By averaging weights, SWAAT moves the model toward a wider, flatter region of the loss surface. This makes the model less sensitive to the small input perturbations used in adversarial attacks.
  • Natural BN Stats Work: One of the most surprising findings is that you don't need adversarial examples to update BN statistics after weight averaging. Natural images provide a sufficient signal, saving significant computation time.
  • Efficiency: SWAAT provides the performance of an ensemble but only requires the inference time and memory of a single model.

Key Results

SWAAT consistently outperformed standard PGD-based adversarial training and other state-of-the-art defenses:

  • CIFAR-10: On a WideResNet-28-10, SWAAT achieved 60.57% accuracy against a PGD-20 attack, compared to 56.23% for standard PGD-AT.
  • CIFAR-100: SWAAT reached 31.07% robustness against PGD-20, significantly higher than the 28.62% of the baseline.
  • SVHN: SWAAT improved PGD-20 robustness from 58.50% to 61.48%.
  • Sanity Check: The model passed the "Obfuscated Gradient Test," meaning its robustness is genuine and not just a result of making the gradients messy or hard for an attacker to follow.

Limitations and Future Work

  • Computational Cost of HEM: While SWAAT itself is efficient, the "Hard Example Mining" (HEM) strategy requires an extra pass over the training data to identify difficult samples, which increases total training time.
  • Hyperparameter Sensitivity: The "SWAAT-window" (how many previous states to average) and the learning rate schedule require careful tuning to balance diversity and stability.
  • Scaling: While tested on CIFAR and SVHN, future work could explore how SWAAT scales to much larger datasets like ImageNet, where the sample complexity issues of adversarial training are even more pronounced.

Summary updated

BibTeX
@inproceedings{hwang2021adversarial,
  author = {Joong-won Hwang and Youngwan Lee and Sungchan Oh and Yuseok Bae},
  title = {{Adversarial Training With Stochastic Weight Average}},
  booktitle = {ICIP},
  year = {2021},
  doi = {10.1109/icip42928.2021.9506548},
}
Figure