Locality-Attending Vision Transformer

Sina Hajimiri, Farzad Beizaee, Fereshteh Shakeri, Christian Desrosiers, Ismail Ben Ayed, Jose Dolz

TL;DR

LocAtViT introduces a modular "add-on" for Vision Transformers (ViTs) that restores local spatial awareness without sacrificing global reasoning. By incorporating a learnable Gaussian attention bias and a novel patch refinement strategy, the authors achieve massive gains in semantic segmentation (up to +6% mIoU) while simultaneously maintaining or improving image classification accuracy.

The Problem: Representation Collapse

Vision Transformers (ViTs) have revolutionized computer vision by using global self-attention to capture long-range dependencies. While this is perfect for image classification (deciding what is in an image), it often fails at dense prediction tasks like semantic segmentation (deciding where every pixel belongs).

The authors identify a "representation collapse" in standard ViTs: as data moves through deeper layers, individual patch tokens lose their unique spatial details and begin to mimic the global [CLS] token. Because standard training only supervises the [CLS] token, the gradients don't "care" if the spatial patches become blurry or indistinct. The challenge is to re-introduce a "locality bias"—similar to the inductive bias found in Convolutional Neural Networks (CNNs)—without losing the transformer's ability to see the big picture.

The Solution: LocAt

The authors propose LocAt (Locality-Attending), which consists of two lightweight components:

  1. Gaussian-Augmented (GAug) Attention: Inside the transformer blocks, the authors modulate the standard attention logits by adding a learnable Gaussian kernel.
  2. How it works: For every patch, the model predicts a variance ($\sigma$) and a scaling factor ($\alpha$) based on the input data. This creates a "soft" bias that encourages patches to pay more attention to their immediate neighbors.
  3. Why it’s clever: Unlike "windowed" attention (which strictly limits the field of view), GAug is a soft nudge. The model can still attend to distant patches if the data demands it, but its "default" state is to prioritize local structure.
  4. Patch Representation Refinement (PRR): This is a parameter-free attention layer inserted just before the classification head.
  5. How it works: It aggregates information across all patches in a non-uniform way before passing the result to the classifier.
  6. The "Aha!" Moment: By involving all patches in the final classification decision, PRR ensures that gradients flow back through every spatial token during training. This prevents the spatial representations from degrading in the final layers, keeping them "sharp" for downstream segmentation tasks.

Key Insights

  • Locality is a Choice, Not a Constraint: Most "local" transformers (like Swin) use hard windows. LocAtViT proves that a data-dependent soft bias is often superior because it allows the model to dynamically balance local detail with global context.
  • Supervision Matters for Structure: The lack of direct supervision on patch tokens is a primary reason ViTs struggle with segmentation. PRR acts as a "segmentation-in-mind" pretraining strategy by forcing the model to maintain high-quality spatial features.
  • Orthogonality: LocAt is designed as a modular upgrade. It can be "plugged into" existing architectures like Swin, RegViT, or RoPEViT, consistently providing a performance boost regardless of the underlying backbone.

Key Results

Performance improvements across various transformer architectures. LocAt consistently improves both segmentation mIoU and classification accuracy.

The quantitative improvements are striking, especially considering the minimal architectural changes:

  • Segmentation Gains: On the ADE20K benchmark, LocAtViT-Tiny achieved a +6.17% mIoU improvement over the vanilla ViT-Tiny. The Base model saw a +4.24% mIoU jump.
  • Classification Bonus: Unlike many methods that trade off classification for segmentation, LocAtViT actually improved ImageNet-1K Top-1 accuracy (e.g., +1.55% for the Tiny model).
  • Foundation Model Synergy: When integrated into DINO (a popular self-supervised model), LocAtViT improved linear classification by +2.13%, proving its effectiveness in label-scarce regimes.

Qualitative Clarity

Comparison of attention maps between standard ViT and LocAtViT. LocAtViT maintains sharp, localized spatial details.

Attention maps show that LocAtViT produces much cleaner, more object-aligned activations compared to the "noisy" and dispersed maps of standard ViTs. The model successfully preserves fine-grained spatial details that are otherwise lost in deeper layers.

Limitations and Future Work

  • Domain Specificity: The study focused exclusively on natural images. Testing on specialized domains like medical imaging or remote sensing remains for future work.
  • Computational Scale: While tested on "Base" models, the authors were unable to test on "Huge" or "Giant" scale foundation models due to massive computational requirements.
  • Windowed Architectures: While LocAt helps windowed models like Swin, the gains are less dramatic because those models already have a "hard-coded" locality bias. LocAt is most transformative for "vanilla" global-attention architectures.

Summary updated

BibTeX
@inproceedings{hajimiri2026locality,
  author = {Sina Hajimiri and Farzad Beizaee and Fereshteh Shakeri and Christian Desrosiers and Ismail Ben Ayed and Jose Dolz},
  title = {{Locality-Attending Vision Transformer}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=KvEjv5klWi},
}
Figure