On the interplay of adversarial robustness and architecture components: patches, convolution and attention

Francesco Croce, Matthias HeinarXiv 2022

Abstract

Recent advancements in computer vision have sparked a debate regarding the inherent adversarial robustness of Vision Transformers (ViTs) compared to traditional Convolutional Neural Networks (CNNs). This paper investigates the specific architectural components that contribute to this resilience. By systematically deconstructing and rebuilding models, we demonstrate that the perceived superiority of ViTs is not solely due to the self-attention mechanism, but rather stems from specific structural choices such as "patchified" input stems and depth-wise convolutions. Our findings show that incorporating these features into standard CNN architectures can significantly bridge the robustness gap.

Introduction

Vision Transformers (ViTs) have gained a reputation for being "natively" more robust to noise and adversarial attacks than CNNs. However, the exact source of this advantage—whether it lies in the attention mechanism, the patch-based input processing, or specific training recipes—has remained unclear. This study aims to isolate these variables to identify the drivers of adversarial robustness and examine how these components influence the interpretability of learned features.

Deconstructing Architectural Robustness

The core of our investigation involves a "ResNet to ConvNeXt" walk, where we progressively modify a standard ResNet-50 to incorporate modern architectural features.

The Power of the Patchify Stem

One of the most significant findings is the impact of the "patchify stem." By dividing the input image into non-overlapping patches at the initial layer, models exhibit improved generalization to unseen attacks. We hypothesize that this acts as a form of dimensionality reduction, making diverse attack types appear more similar to the model's internal representation.

Interpretability as a Side Effect

Adversarial training (AT) does more than just increase robust accuracy; it fundamentally changes how models perceive images. In robustly trained models, internal representations become significantly cleaner and more focused on the primary object of interest.

Figure 2: Comparison of attention maps in plainly trained vs. adversarially trained models. Adversarial training results in much cleaner, object-focused visualizations.

As shown in the figure above, while plainly trained models often exhibit noisy or scattered attention, adversarially trained models (both Transformers and CNNs) learn to ignore background clutter and focus on salient features, similar to models trained via self-supervision.

Comparative Analysis of Architectures

Our experiments compare standard and robust versions of DeiT-S, XCiT-S, and ResNet-50. We observe that while Transformers often generalize better to "unseen" threat models (like $\ell_2$ or $\ell_1$ perturbations), modernized CNNs can achieve superior performance in specific categories like $\ell_\infty$ robustness.

Figure 3: Saliency map comparisons across DeiT-S, XCiT-S, and ResNet-50 under plain and adversarial training regimes.

Key Results

  • Closing the Gap: A standard ResNet-50 achieves a robust accuracy of 36.7% against $\ell_\infty$ attacks. By adding a patchify stem, GELU activations, and depth-wise convolutions, we boosted this to 44.0%.
  • ConvNeXt Superiority: A trained ConvNeXt-T reached 46.2% robust accuracy, outperforming the specialized XCiT Transformer (41.7%) and the baseline ResNet-50 by nearly 10%.
  • Grid Sensitivity: Naturally trained ViTs are particularly sensitive to the alignment of adversarial patches; attacks are more effective when they overlap the intersection of four tokens rather than a single token.

Conclusion

The gap in adversarial robustness between ViTs and CNNs is not a fundamental divide between attention and convolution. Instead, it is largely a product of modern design choices. By adopting patchified stems and depth-wise convolutions, CNNs can match or even exceed the robustness of state-of-the-art Transformers. Future work will focus on whether these insights scale to larger model variants and the theoretical underpinnings of why patchification aids dimensionality reduction in the context of adversarial defense.

Summary updated

BibTeX
@misc{croce2022interplay,
  author = {Francesco Croce and Matthias Hein},
  title = {{On the interplay of adversarial robustness and architecture components: patches, convolution and attention}},
  year = {2022},
  eprint = {2209.06953},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2209.06953},
}
Figure