Are Vision Transformers Robust to Patch Perturbations?

Jindong Gu, Volker Tresp, Yao Qin

Abstract

While Vision Transformers (ViTs) demonstrate remarkable resilience to natural "patchy" noise—often outperforming CNNs by effectively ignoring corrupted areas—they are significantly more vulnerable to targeted adversarial patch attacks. This research reveals that the attention mechanism, which facilitates robustness against random noise, can be "hijacked" by an adversary to redirect the model's focus toward a malicious patch. We explore these vulnerabilities and evaluate a mitigation strategy called Smoothed Attention.

Introduction: The Patch-Based Representation

As Vision Transformers (ViTs) emerge as powerful alternatives to Convolutional Neural Networks (CNNs), understanding their unique "blind spots" is critical. Unlike CNNs, which process images through local sliding windows, ViTs decompose an image into a sequence of discrete patches and utilize global self-attention to model relationships between them. This architecture prompts a fundamental question: how robust is this patch-based representation? While prior studies focused on global image perturbations, this work specifically investigates the impact of corrupting individual patches—either through "natural" noise (e.g., blur, pixelation) or "adversarial" noise designed to deceive the model.

Methodology

The study conducts a head-to-head comparison between ViTs (specifically DeiT) and CNNs (ResNet). To ensure a fair comparison, "fair base models" were utilized, matched for parameter count, training recipes, and clean-image accuracy.

Key experimental techniques included:

  • Patch-wise Perturbations: Randomly corrupting $n$ patches with 15 types of natural noise or targeting them with white-box adversarial attacks.
  • Visual Analysis: Employing Attention Rollout and Vanilla Gradient Maps to visualize model focus during misclassifications.
  • Smoothed Attention: A proposed defense adding a temperature parameter ($T > 1$) to the softmax operation in the self-attention layer. This "smooths" attention weights, preventing excessive focus on any single adversarial patch.

The primary evaluation used ImageNet-1k, calculating the Fooling Rate (FR)—the percentage of correctly classified images that the model fails on after patch perturbation.

The Dual Nature of Attention: Hijacking and Filtering

A central finding is the "Attention Hijack." In the presence of natural noise, the attention mechanism acts as a filter, assigning low weights to corrupted patches. However, adversarial patches are mathematically optimized to "attract" attention. The model is effectively tricked into ignoring the primary object and focusing entirely on the malicious patch.

Visualizing the attention hijack: adversarial patches attract the model's focus away from the main object.

Further insights include:

  • Spatial Vulnerability: CNNs exhibit a "center-bias," making them harder to fool if an adversarial patch is in a corner. Conversely, ViTs are equally vulnerable regardless of patch placement because they treat patches as a sequence, lacking the inherent spatial hierarchy of CNNs.
  • Grid Sensitivity: Adversarial attacks on ViTs are highly sensitive to alignment; shifting a patch by a single pixel can drastically reduce attack effectiveness if it no longer aligns with the internal grid.
  • Architectural Variations: Hierarchical models like Swin Transformers and attention-free models like Mixer-MLPs demonstrate greater robustness than standard ViTs.

Quantitative Results

The experiments highlight a stark contrast between natural robustness and adversarial vulnerability.

Natural Robustness

ViTs generally outperform CNNs when facing random, non-adversarial corruptions. For instance, when 32 patches were naturally corrupted, DeiT-small maintained a low Fooling Rate of 1.8%, compared to 3.7% for ResNet50.

Fooling rates for natural corruption across different patch sizes for ResNet and DeiT models.

Adversarial Vulnerability and Defense

The trend reverses under targeted attack. A single adversarial patch achieved a 61.5% Fooling Rate on DeiT-small, nearly double the 30.6% rate for ResNet50. However, the Smoothed Attention technique proved effective, reducing the adversarial Fooling Rate for DeiT-small from approximately 60% to 40% with minimal impact on clean-image accuracy.

Conclusion and Future Directions

While Smoothed Attention provides a significant defense, a gap remains between ViTs and CNNs regarding adversarial patch robustness. This study primarily addresses "white-box" scenarios; future work should explore "black-box" transfers and real-world physical attacks, such as stickers on signage. The findings suggest that incorporating hierarchical structures, as seen in the Swin Transformer, may be essential for developing the next generation of robust vision architectures.

Summary updated

BibTeX
@inproceedings{gu2022are,
  author = {Jindong Gu and Volker Tresp and Yao Qin},
  title = {{Are Vision Transformers Robust to Patch Perturbations?}},
  booktitle = {European Conference on Computer Vision},
  year = {2022},
  doi = {10.1007/978-3-031-19775-8\_24},
}
Figure