TL;DR
Researchers have introduced LookHere, a drop-in replacement for position encoding in Vision Transformers (ViTs) that enables models to handle high-resolution images far better than current state-of-the-art methods. By using 2D attention masks to restrict attention heads to specific directions and fields of view, LookHere achieves a massive 21.7% accuracy lead over 2D-RoPE when extrapolating from $224^2$ to $1024^2$ resolution.
The Extrapolation Problem in Vision Transformers
In computer vision, higher resolution usually means better accuracy because there is more detailed scene information. However, training models natively on high-resolution images is prohibitively expensive. The "holy grail" is extrapolation: training a model on low-resolution images (like $224^2$ px) and deploying it on high-resolution images (like $1024^2$ px) without any additional training.
While Vision Transformers (ViTs) are theoretically flexible with sequence length, they often fail miserably at this task. The authors identify position encodings as the primary culprit. Standard methods (like absolute or rotary embeddings) create a "distribution shift" when the number of patches increases at test time. This confuses the attention heads and leads to "attention collapse," where the model loses track of spatial relationships entirely.
Methods: Directed Attention with LookHere
The authors propose LookHere, which moves away from traditional position embeddings added to the input. Instead, it modifies the attention mechanism directly to enforce spatial structure.
- Directed Attention Masks: Each attention head is assigned a fixed "Field of View" (FOV) and a direction (e.g., North, South, Northeast). This forces heads to look in specific directions relative to the query patch.
- 2D Distance Penalties: Within a head's FOV, attention scores are penalized based on the Euclidean distance between patches. This hard-codes a sense of "near vs. far."
- Translation Equivariance: Because the masks and penalties are relative to the query patch rather than absolute coordinates, the model naturally handles objects regardless of where they appear in the frame.
- Head Diversity: By assigning different directions to different heads (e.g., 8 directed heads and 4 undirected heads in a ViT-B), the model is guaranteed to maintain a diverse set of spatial features, preventing the redundancy often seen in standard ViTs.
Datasets and Evaluation
The models were trained on ImageNet-1k at $224^2$ resolution. Evaluation was performed across several standard benchmarks, including ImageNet-Val, ReaL, and v2 for standard classification, and ImageNet-A and -R for adversarial and rendition robustness.
Crucially, the authors introduced ImageNet-HR, a natively high-resolution test set consisting of 5,000 images at $1024^2$ px. Unlike artificially upsampled datasets, these images contain true high-frequency detail, providing a much cleaner evaluation of a model's extrapolation capabilities.
Key Insights
- Preventing Attention Collapse: Standard ViTs often suffer from "attention collapse" at deeper layers, where all patches start looking the same to the model. LookHere’s structural constraints prevent this, maintaining distinct patch representations throughout the network.
- The "Small Object" Advantage: Extrapolation benefits images with small objects the most. At higher resolutions, these objects occupy more patches, and LookHere allows the model to actually "see" that extra detail rather than being overwhelmed by the increased sequence length.
- Zero-Cost Scaling: LookHere requires almost no extra computation (accounting for only 0.016% of total FLOPs) and doesn't require the global slope tuning that other methods like 2D-ALiBi or 2D-RoPE need to perform well at higher resolutions.
Key Results
LookHere demonstrates remarkable improvements in both standard performance and high-resolution extrapolation.
- Massive Extrapolation Gains: When trained at $224^2$ and tested at $1024^2$, LookHere outperformed the previous best method (2D-RoPE) by 21.7% on ImageNet.
- Better "Out of the Box": Even without changing resolution, LookHere improved average classification accuracy by 1.6% and boosted adversarial robustness by 5.4%.
- Improved Calibration: The models were better "calibrated," meaning their confidence scores more accurately reflected their actual likelihood of being correct (decreasing calibration error by 1.5%).
- Finetuning Synergy: When the model was finetuned on higher resolutions, LookHere started from a much better baseline, retaining its performance advantage over other architectures.
Limitations and Future Work
The authors acknowledge that LookHere currently relies on hand-designed directional masks and distance penalties. While their ablation studies show the method is robust to different configurations, future work could involve learning these masks or making them dynamic based on the input.
Additionally, while the experiments focused on the common ViT-B/16 architecture, the authors are interested in scaling LookHere to "giant" models and extending the directed attention concept to video (adding a temporal dimension) and 3D point clouds. They also noted that the structured sparsity of the masks could be exploited by custom CUDA kernels to significantly speed up attention computation in the future.
Summary updated