Transformers in Vision: A Survey

Salman Khan, Muzammal Naseer, Munawar Hayat, Syed Waqas Zamir, Fahad Shahbaz Khan, Mubarak Shah · DOI

TL;DR

This survey provides a comprehensive map of how Transformer architectures, originally designed for natural language, are fundamentally reshaping computer vision. By replacing or augmenting traditional convolutional networks with self-attention mechanisms, these models excel at capturing long-range dependencies and scaling to massive datasets, achieving state-of-the-art results in everything from image classification to 3D analysis.

What Problem Does This Paper Address?

For years, Convolutional Neural Networks (CNNs) have been the bedrock of computer vision. However, CNNs have inherent limitations: their "receptive field" is local, meaning they struggle to model relationships between distant parts of an image without many layers. Furthermore, their weights are static after training, applying the same filters regardless of the specific input content.

As Transformers revolutionized Natural Language Processing (NLP) by modeling global context through self-attention, the vision community began asking: Can we treat an image like a sequence of words? This paper surveys the explosion of research attempting to adapt the Transformer's strengths—scalability, minimal inductive bias, and dynamic global modeling—to the complex, high-dimensional world of visual data.

Methods

The core engine of these models is Self-Attention, which calculates the relevance of every element in a sequence to every other element.

Fig. 2: An example self-attention block used in the vision domain [39]. Given the input sequence of image features, the triplet of (key, query, value) is calculated followed by attention calculation and applying it to reweight the values. A single head is shown here and an output projection (W) is finally applied to obtain output features with the same dimension as the input. Figure adapted from [39].

The authors categorize the "Vision Transformer" (ViT) landscape into several architectural strategies:

  • Uniform-scale ViTs: Models like the original ViT "patchify" an image—breaking it into a sequence of 16x16 flattened patches—and process them through standard Transformer blocks.
  • Multi-scale/Hierarchical ViTs: Models like Swin Transformer or PVT introduce a pyramid structure (similar to CNNs) to handle high-resolution images more efficiently by gradually reducing the number of tokens.
  • Hybrid Designs: These combine the strengths of both worlds, using CNN layers to capture low-level local textures and Transformers to handle high-level global reasoning (e.g., CvT, LeViT).
  • Self-Supervised ViTs: Approaches like DINO and MoCo v3 allow Transformers to learn powerful representations from massive unlabeled datasets, often discovering object boundaries automatically.
Fig. 4: A taxonomy of self-attention design space. Existing approaches based on self-attention explore single-head or multi-head (transformer) designs for vision tasks. We note that interesting efforts have been made to utilize knowledge from convolution based architectures to improve ViTs (e.g., multi-scale and hybrid designs). We categorize the upcoming sections of this survey according to the types of self-attention block (left tree diagram) as well as the prominent tasks in computer vision (right).

Datasets

The survey reviews models evaluated across a vast array of benchmarks:

  • Classification: ImageNet-1K, ImageNet-21K, and the massive JFT-300M.
  • Detection/Segmentation: COCO, Cityscapes, ADE20K, and Mapillary Vistas.
  • Video: Kinetics-400/600/700, UCF101, and ActivityNet.
  • Multi-modal: Conceptual Captions, MS-COCO Captions, and Wikipedia.
  • 3D/Low-level: ModelNet40 (3D), DIV2K (Super-resolution), and CUFED5.

Key Insights and Ideas

  • Minimal Inductive Bias: Unlike CNNs, which assume "locality" and "translation invariance," Transformers learn the structure of the problem from the data itself. This makes them more flexible but also more "data-hungry."
  • Dynamic Receptive Fields: While a CNN filter is fixed, a Transformer's attention map changes for every image. It can focus on a tiny detail or the entire scene simultaneously.
  • The Power of Pre-training: Much like BERT in NLP, Vision Transformers show their true potential when pre-trained on massive datasets (like JFT-300M) before being fine-tuned for specific tasks.
  • Unified Modality: Because Transformers treat everything as a sequence of tokens, they are the perfect "universal" architecture for multi-modal tasks, allowing text, images, and audio to be processed in a single shared space (e.g., CLIP, DALL-E).
Fig. 6: An overview of Vision Transformer (on the left) and the details of Transformer encoder (on the right). The architecture resembles Transformers used in the NLP domain and the image patches are simply fed to the model after flattening. After training, the feature obtained from the first token position is used for classification. Image obtained from [11].

Key Results

  • State-of-the-Art Accuracy: ViT-L achieved 88.55% top-1 accuracy on ImageNet, outperforming top-tier CNNs like ResNet.
  • Simplified Pipelines: The DETR (Detection Transformer) model removed the need for complex, hand-crafted components like Non-Maximum Suppression (NMS) and Region Proposal Networks (RPN), treating detection as a simple set-prediction problem.
  • Zero-Shot Mastery: OpenAI’s CLIP, using a Transformer backbone, demonstrated the ability to classify images from 30 different benchmarks with 75% accuracy on ImageNet without ever seeing a single training label from that dataset.
  • Generative Breakthroughs: DALL-E showed that Transformers could generate high-fidelity, creative images from complex text prompts by modeling the joint distribution of text and image tokens.

Limitations and Future Work

Despite their success, the authors highlight several "open challenges":

  • High Computational Cost: The standard self-attention mechanism has a quadratic complexity $O(n^2)$ relative to the number of patches. This makes processing high-resolution images or long videos extremely expensive.
  • Data Requirements: Without the built-in assumptions of CNNs, small-scale training often leads to poor performance. Finding ways to make Transformers "data-efficient" (like the DeiT distillation approach) is a major research thrust.
  • Interpretability: Understanding why a Transformer made a specific decision is difficult because attention weights get inter-mixed across many layers.
  • Hardware Efficiency: Most current ViTs are optimized for GPUs; deploying them on edge devices or specialized hardware like FPGAs remains a hurdle.

The survey concludes that we are moving toward modality-agnostic systems—like the Perceiver—that can process any input type using the same fundamental Transformer blocks.

Summary updated

BibTeX
@article{khan2022transformers,
  author = {Salman Khan and Muzammal Naseer and Munawar Hayat and Syed Waqas Zamir and Fahad Shahbaz Khan and Mubarak Shah},
  title = {{Transformers in Vision: A Survey}},
  journal = {ACM Computing Surveys},
  year = {2022},
  doi = {10.1145/3505244},
}
Figure