TL;DR
LookHere is a novel position encoding method for Vision Transformers (ViTs) that replaces standard learnable embeddings with fixed 2D directional masks and distance-based biases. It enables ViTs to "extrapolate" to much higher resolutions at test time without any additional training, outperforming state-of-the-art methods like 2D-RoPE by over 20% on high-resolution benchmarks.
What Problem Does This Paper Address?
Vision Transformers (ViTs) are powerful, but they are notoriously rigid regarding image resolution. If you train a ViT on $224^2$ pixel images and try to run it on $1024^2$ images, performance typically collapses. This is a major hurdle because high-resolution images contain vital details, but training models on them from scratch is prohibitively expensive.
The authors identify position encoding (PE) as the culprit. Standard PE methods (like learnable 1D or 2D vectors) create a massive "distribution shift" when the number of patches changes at test time. The model essentially "gets lost" because the spatial coordinates it learned during training no longer match the input.
Methods
The authors propose LookHere, a drop-in replacement for standard position encodings that uses hard-coded spatial priors instead of learned vectors.
- Directed Attention Masks: Instead of letting every attention head look everywhere, LookHere restricts most heads to a specific Field of View (FOV). For example, one head might only be allowed to "look right" in a 90° cone.
- 2D Distance Biases: Within that FOV, attention scores are penalized based on the Euclidean distance between patches. This encourages heads to focus on local context while maintaining a sense of global direction.
- Head Diversity: By assigning different cardinal (↑, ↓, ←, →) and intercardinal (↗, ↘, ↙, ↖) directions to different heads, the model is forced to maintain a diverse set of spatial features.
Datasets
The researchers evaluated LookHere on the standard ImageNet-1k suite, including robustness variants like ImageNet-A, -R, and -v2.
Crucially, they introduced ImageNet-HR, a new test set of 5,000 natively high-resolution ($1024^2$ px) images. Unlike standard datasets that are often upsampled (which introduces blur), ImageNet-HR provides a clean benchmark for true high-resolution classification.
Key Insights and Ideas
-
Preventing Attention Collapse: Standard ViTs often suffer from "attention collapse" in deeper layers, where different heads start doing the same thing. LookHere’s directional constraints prevent this, maintaining high head diversity throughout the network. LookHere maintains significantly higher attention head diversity (measured by JS Divergence) compared to baseline methods.
-
Small Objects Benefit Most: The paper finds that extrapolation helps most for images containing small objects. These objects are spread across more patches at high resolutions, and LookHere’s stable spatial mapping allows the model to "zoom in" effectively.
- Zero-Shot Segmentation: Because LookHere preserves spatial relationships so well, the internal patch representations remain "faithful" to their original locations. This allows for surprisingly good semantic segmentation using a simple "logit lens" technique without any segmentation-specific training. By restricting attention, LookHere produces patch representations that are spatially accurate enough to act as a zero-shot segmentation map.
Key Results
- Extreme Extrapolation: When trained at $224^2$ and tested at $1024^2$, LookHere outperformed the previous state-of-the-art (2D-RoPE) by 21.7% on ImageNet.
- General Performance: Even without resolution changes, LookHere improved standard ImageNet classification by 1.6% on average.
- Robustness and Calibration: The method increased adversarial robustness by 5.4% and reduced model calibration error by 1.5%, suggesting that diverse attention heads lead to more reliable "ensembles" within a single model.
Limitations and Future Work
The primary limitation is that the directional masks and distance penalties are currently hand-designed. While the authors showed the method is robust to the specific choice of slopes and angles, a more automated way to determine these configurations could be beneficial.
Additionally, the experiments focused on the standard ViT-B/16 scale. Future work includes scaling LookHere to "giant" models, applying it to video (where temporal direction matters), and developing custom sparse attention kernels to turn the masked attention into a significant speed boost.
Summary updated