Prepare for the Worst: Generalizing across Domain Shifts with Adversarial Batch Normalization

Manli Shu, Zuxuan Wu, Micah Goldblum, Tom Goldstein

Abstract

Adversarial training is the industry standard for producing models that are robust to small adversarial perturbations. However, machine learning practitioners need models that are robust to other kinds of changes that occur naturally, such as changes in the style or illumination of input images. Such changes in input distribution have been effectively modeled as shifts in the mean and variance of deep image features. We adapt adversarial training by directly perturbing feature statistics, rather than image pixels, to produce models that are robust to various unseen distributional shifts. We explore the relationship between these perturbations and distributional shifts by visualizing adversarial features. Our proposed method, Adversarial Batch Normalization (AdvBN), is a single network layer that generates worst-case feature perturbations during training. By fine-tuning neural networks on adversarial feature distributions, we observe improved robustness of networks to various unseen distributional shifts, including style variations and image corruptions. In addition, we show that our proposed adversarial feature perturbation can be complementary to existing image space data augmentation methods, leading to improved performance.

Introduction

Deep learning models are notoriously brittle when faced with real-world distribution shifts. A model trained on crisp, clear photos often fails when encountering rain, different camera filters, or artistic sketches. While standard adversarial training—which perturbs input pixels—is the gold standard for defending against malicious noise, it does not necessarily improve robustness to these natural stylistic changes.

The challenge lies in the fact that "style" is difficult to define mathematically at the pixel level. However, research in style transfer has shown that the mean and variance of deep feature maps effectively encode the stylistic properties of an image. The authors of this paper propose Adversarial Batch Normalization (AdvBN), a method that uses adversarial optimization to find the "worst-case" style during training, forcing the model to become resistant to deceptive stylistic shifts.

The AdvBN Method

AdvBN introduces a new network layer that operates during the training phase through a min-max optimization game:

  1. The Adversarial Game: For a given batch of images, an adversary attempts to shift the feature statistics (mean $\mu$ and variance $\sigma$) within a specific bound ($\epsilon$) to maximize the model's classification error.
  2. PGD on Statistics: Unlike standard attacks on pixels, AdvBN applies Projected Gradient Descent (PGD) directly to the normalization parameters. This searches for the most "confusing" version of the current features.
  3. Auxiliary BNs: To prevent the model from losing accuracy on "clean" images, the researchers use a dual-path approach: one set of Batch Norm statistics for clean data and another "adversarial" set for the perturbed data.

Visualizing the Adversary

To understand what the AdvBN layer is doing, the authors passed adversarially shifted features through a decoder. These visualizations reveal that the adversary successfully strips away the specific textures and colors the model might over-rely on, forcing the network to focus on more robust, structural object features.

Original clean image used for feature analysis.

Key Results and Insights

AdvBN consistently outperformed standard training and other specialized robustness methods across several "out-of-distribution" benchmarks:

  • ImageNet Variants: On ImageNet-Sketch, AdvBN improved Top-1 accuracy from 24.1% to 27.9%. When combined with AutoAugment, it reached 30.3%.
  • Corruption Resistance: On ImageNet-C (75 types of visual corruptions), AdvBN reduced the Mean Corruption Error (mCE) from 76.7 to 72.7. When combined with AugMix, it achieved a state-of-the-art 64.6.
  • Semantic Segmentation: In cross-domain tests on the Synthia dataset, AdvBN achieved the highest Mean IoU across almost all source-target pairs (e.g., training on "Spring" and testing on "Winter").

One of the most significant findings is that AdvBN is complementary to existing image-space data augmentation methods. Because it operates in the feature space rather than the image space, it can be stacked on top of methods like AugMix for cumulative performance gains.

Conclusion

AdvBN offers a novel way to generalize across domain shifts by treating style as an adversarial perturbation. By forcing models to handle the "worst" possible feature distributions, they become naturally robust to a wide variety of unseen styles and corruptions. While there is a slight trade-off in clean data accuracy, the use of auxiliary BNs effectively mitigates this "robustness tax." Future work may explore applying these feature-space perturbations to other modalities like Natural Language Processing.

Summary updated

Abstract

Adversarial training is the industry standard for producing models that are robust to small adversarial perturbations. However, machine learning practitioners need models that are robust to other kinds of changes that occur naturally, such as changes in the style or illumination of input images. Such changes in input distribution have been effectively modeled as shifts in the mean and variance of deep image features. We adapt adversarial training by directly perturbing feature statistics, rather than image pixels, to produce models that are robust to various unseen distributional shifts. We explore the relationship between these perturbations and distributional shifts by visualizing adversarial features. Our proposed method, Adversarial Batch Normalization (AdvBN), is a single network layer that generates worst-case feature perturbations during training. By fine-tuning neural networks on adversarial feature distributions, we observe improved robustness of networks to various unseen distributional shifts, including style variations and image corruptions. In addition, we show that our proposed adversarial feature perturbation can be complementary to existing image space data augmentation methods, leading to improved performance. The source code and pre-trained models are released at \url{https://github.com/azshue/AdvBN}.
BibTeX
@inproceedings{shu2021prepare,
  author = {Manli Shu and Zuxuan Wu and Micah Goldblum and Tom Goldstein},
  title = {{Prepare for the Worst: Generalizing across Domain Shifts with Adversarial Batch Normalization}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=qtxl-4l2iWG},
}
Figure