Robustifying Token Attention for Vision Transformers

Yong Guo, David Stutz, Bernt Schiele

Abstract

Vision Transformers (ViTs) have demonstrated state-of-the-art performance across various computer vision tasks but remain notably fragile when faced with common image corruptions such as noise, blur, or weather effects. This paper identifies "token overfocusing"—the tendency of self-attention mechanisms to rely on a sparse, fragile subset of tokens—as a primary driver of this lack of robustness. To address this, we introduce two complementary techniques: Token-aware Average Pooling (TAP), which adaptively aggregates local context to smooth representations, and Attention Diversification Loss (ADL), which encourages models to attend to a broader set of features. Our methods significantly improve robustness across multiple architectures (FAN, RVT, DeiT, Swin) with negligible computational overhead.

Introduction

While Vision Transformers have revolutionized the field of computer vision, they possess a significant "glass jaw": their accuracy often plummets when encountering common image corruptions like Gaussian noise or motion blur. This vulnerability limits their deployment in safety-critical real-world applications.

Through empirical analysis, we identify the culprit for this fragility: token overfocusing. In standard ViTs, the self-attention mechanism tends to concentrate on a very small number of "important" tokens across all heads and layers. If these few tokens are distorted by noise, the entire attention pattern collapses or shifts drastically. Essentially, the model places its entire predictive weight on a small, unstable foundation.

Proposed Methodology

To mitigate token overfocusing and spread the "attention budget" more effectively, we propose a two-pronged approach.

1. Token-aware Average Pooling (TAP)

Standard ViTs treat tokens as isolated points before the attention step, which makes them susceptible to point-wise noise. TAP is a lightweight module inserted before self-attention that allows each token to aggregate information from its local neighborhood.

Unlike fixed pooling methods, TAP utilizes a multi-branch structure with varying dilations. A lightweight "dilation predictor" learns to choose the optimal pooling area for each token dynamically. This ensures that if a single pixel is corrupted, its neighbors can help "smooth out" the representation, providing a more stable input for the attention mechanism. Our analysis shows that applying TAP specifically to the middle and deep layers of the transformer yields the highest robustness gains, as these layers are most prone to overfocusing.

2. Attention Diversification Loss (ADL)

ADL is a training-time constraint designed to discourage feature redundancy. It calculates the cosine similarity between the attention vectors of different tokens and penalizes high similarity. By doing so, the loss forces different output tokens to attend to different parts of the input image.

To account for the naturally sparse nature of attention, we include a thresholding trick ($\tau$) that ignores negligible attention weights during the similarity calculation. This prevents the loss from being dominated by irrelevant background noise and focuses the diversification on the most salient features.

Experimental Results

Robustness Benchmarks

We evaluated our methods on top of several state-of-the-art architectures, including FAN, RVT, DeiT, and Swin, using the ImageNet-C (common corruptions), ImageNet-A (natural adversarial examples), ImageNet-R (renditions), and ImageNet-P (perturbations) datasets.

On the already-robust FAN-B-Hybrid model, adding TAP and ADL improved the mean corruption error (mCE) by 2.4%. Notably, this improvement did not come at the cost of performance on clean data; in fact, clean accuracy increased by 0.4%.

Semantic Segmentation

To test the generalizability of our approach, we performed fine-tuning for semantic segmentation on the Cityscapes and ACDC (Adverse Conditions Dataset with Corruptions) benchmarks. The results demonstrated a 2.4% mIoU improvement on Cityscapes-C and a 3.0% improvement on ACDC, which includes challenging conditions like fog, rain, and night.

Efficiency and Complexity

A key advantage of our approach is its efficiency. TAP adds almost no computational cost. For a FAN-B model, it increased parameters by only ~0.3M (on a 50M base) and FLOPs by a negligible 0.1G.

Discussion and Insights

Our analysis reveals that when ADL is applied, attention maps exhibit a clear "diagonal pattern." This indicates that tokens prioritize their own information while still aggregating context from others, creating a form of "residual learning" for attention.

By forcing diversity via ADL, the model creates a redundant system. In standard ViTs, many attention heads end up looking at the same few pixels, creating a single point of failure. Our method ensures that if one set of features is obscured by noise, other heads are already trained to find signal elsewhere in the image. This redundancy is a significant asset for model reliability.

Conclusion and Future Work

This paper demonstrates that addressing token overfocusing is a highly effective strategy for robustifying Vision Transformers. By combining adaptive local aggregation (TAP) with a diversification constraint (ADL), we can significantly enhance a model's ability to handle noise and blur without sacrificing efficiency or clean-data performance.

Future work could explore more sophisticated ways to predict pooling areas beyond the current linear predictor or investigate the application of these techniques to extremely high-resolution images, where token redundancy is even more pronounced.

Summary updated

BibTeX
@inproceedings{guo2023robustifying,
  author = {Yong Guo and David Stutz and Bernt Schiele},
  title = {{Robustifying Token Attention for Vision Transformers}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2023},
}
Figure