Vision Transformers (ViTs) have fundamentally changed computer vision, but they have a "memory" problem. As data flows through the deep layers of a standard ViT, the features tend to become increasingly similar—a phenomenon known as feature collapse. By the time you reach the final layers, the model has often traded fine-grained local details (like edges and textures) for a blurry, overly-global view of the image.
A new paper, "ReViT: Enhancing Vision Transformers Feature Diversity with Attention Residual Connections," proposes a deceptively simple fix: if we have residual connections for features, why not have them for attention itself?
TL;DR
ReViT introduces Residual Attention, a mechanism that propagates attention scores from shallower to deeper layers via a learnable gate. This prevents "feature collapse," allowing deep layers to retain crucial low-level details, resulting in significant accuracy gains (+4.6% on ImageNet-1K) and improved robustness to scaling and translation.
What Problem Does This Paper Address?
The core issue is self-attention over-globalization. In a standard ViT, each layer's attention mechanism tries to model relationships between all patches in an image. As the network gets deeper, tokens aggregate so much information from their neighbors that they become indistinguishable.
This leads to two main drawbacks:
- Loss of Diversity: The model "forgets" the local shapes and edges necessary for precise recognition.
- Data Hunger: Because they lack the inherent "spatial inductive bias" of CNNs (which naturally look at local neighborhoods), standard ViTs require massive datasets to learn effectively.
Previous attempts to fix this often involved making Transformers look more like CNNs (e.g., using windowed attention), but these can sacrifice the Transformer's ability to model long-range dependencies.
Methods
The authors propose the Residual Attention Vision Transformer (ReViT). The key innovation is the Residual Attention Module, which changes how the raw attention scores ($S$) are calculated.
In a standard ViT, the attention scores for layer $l$ are just the scaled dot-product of Queries ($Q$) and Keys ($K$): $$S_l = \frac{Q_l K_l^T}{\sqrt{d}}$$
ReViT modifies this by adding a residual connection from the previous layer's scores: $$S_l = \alpha \left( \frac{Q_l K_l^T}{\sqrt{d}} \right) + (1 - \alpha) S_{l-1}$$
Here, $\alpha$ is a learnable gate (or a set of layer-specific gates $\alpha_l$). This allows the network to decide, layer by layer, how much "new" global information to incorporate versus how much "old" local relationship information to preserve. By carrying forward the attention maps from earlier layers, the deeper layers are forced to remember the spatial relationships that defined low-level features.
Datasets
The authors evaluated ReViT across a diverse range of benchmarks:
- Large-scale: ImageNet-1K (over 1 million images).
- Small-scale: CIFAR-10 and CIFAR-100.
- Fine-grained: Oxford Flowers-102 and Oxford-IIIT Pet.
- Downstream Tasks: COCO2017 for object detection and instance segmentation.
Key Insights and Ideas
- Slowing Down Globalization: Using a "non-locality metric," the authors proved that ReViT keeps some attention heads "local" even in deep layers, whereas standard ViT heads all become global very quickly.
- Feature Diversity: As shown in Figure 3, the cosine similarity between patches in ReViT stays lower in deep layers compared to standard ViT. This means the patches remain distinct and informative rather than collapsing into a uniform representation.
- Visual Evidence: GradCAM visualizations (Figure 1 and 8) show that ReViT's final layers produce feature maps that tightly align with the actual shape of the object, while standard ViT maps are often fragmented or overly diffuse.
Key Results
- ImageNet-1K: ReViT-B achieved 82.4% top-1 accuracy, a massive +4.6% improvement over the standard ViT-B (77.8%) with zero additional parameters (when using a single $\alpha$).
- Small Datasets: On CIFAR-100, ReViT improved accuracy by 3.4%, demonstrating that preserving low-level features is especially helpful when data is scarce.
- Robustness: In tests where images were shifted or scaled, ReViT showed significantly less performance degradation. For example, at 60% scale reduction, ReViT-B outperformed ViT-B by 19.5 percentage points.
- Versatility: The module is "plug-and-play." When added to multi-scale models like Swin-T and MViTv2-T, it consistently improved mAP for object detection and instance segmentation on COCO.
Limitations and Future Work
While ReViT shows great promise, the authors note a few areas for further exploration:
- Modality Generalization: The study focused entirely on images. It remains to be seen if residual attention helps in NLP or audio tasks.
- Extreme Scale: The experiments were conducted on "Base" and "Tiny" models. The impact on "Huge" models trained on billions of images (like ViT-H) is currently unknown.
- Future Directions: The authors suggest investigating how controlling attention globality impacts the explainability of these models and exploring the identification of "dominant tokens" to further unify feature representations.
Summary updated