Visual Transformers: Where Do Transformers Really Belong in Vision Models?

Bichen Wu, Chenfeng Xu, Xiaoliang Dai, Alvin Wan, Peizhao Zhang, Zhicheng Yan, Masayoshi Tomizuka, Joseph Gonzalez, Kurt Keutzer, Peter Vajda

Abstract

While Vision Transformers (ViT) have revolutionized computer vision, their reliance on dense pixel-grid patches often leads to computational inefficiency. This paper introduces the Visual Transformer (VT), a hybrid architecture that leverages convolutions for low-level feature extraction and Transformers for high-level semantic reasoning. By representing images as a compact set of "semantic tokens" rather than a dense grid, VT achieves superior accuracy and efficiency compared to pure convolutional (ResNet) and pure Transformer (ViT) models across classification and segmentation tasks.

Introduction

Traditional convolutional neural networks (CNNs) have long dominated computer vision but suffer from three primary limitations: spatial inefficiency (treating all pixels equally), concept redundancy (applying high-level filters everywhere), and local constraints (difficulty modeling long-range dependencies). Conversely, pure Transformers like ViT address long-range dependencies but are "pixel-dense," modeling relationships between every single patch, which is computationally expensive and redundant in early network stages.

The authors propose that Transformers are most effective when operating on high-level semantic concepts rather than raw pixels. The Visual Transformer (VT) bridges this gap by using a hybrid approach: convolutions handle early-stage local features, while a Transformer processes a small set of learned semantic tokens in the later stages.

The Visual Transformer Architecture

The core of the VT module is the transition from pixel space to a compact "token space." The module consists of three primary components:

  1. The Tokenizer: Instead of fixed patches, the tokenizer uses spatial attention to group pixels into a small set of semantic tokens (typically 16). This can be done via a filter-based approach or a recurrent approach that uses tokens from previous layers to guide extraction.
  2. The Transformer: A standard self-attention mechanism operates on these few semantic tokens. Because the token count is low, this stage is significantly faster than the dense attention used in ViT.
  3. The Projector: For dense prediction tasks like semantic segmentation, the projector maps the processed tokens back onto the original feature map to restore spatial resolution.
The Visual Transformer (VT) architecture overview, illustrating the Tokenizer, Transformer, and Projector components.

Key Insights: Semantic Token Space

The fundamental shift in VT is moving from "pixel space" to "token space." Similar to how a sentence uses a few words to describe a scene, VT uses a few visual tokens to represent high-level concepts (e.g., "sheep," "grass"). Visualizations confirm that these tokens automatically learn to focus on distinct semantic regions without explicit supervision. Furthermore, the use of input-dependent weights (content-awareness) allows the same tokens to represent different concepts across different images, unlike fixed-weight graph convolutions.

Experimental Results

The VT architecture was evaluated on ImageNet (classification), COCO-stuff, and LIP (segmentation).

Classification Performance

On ImageNet, VT-ResNets outperformed standard ResNets by 4.6 to 7 points. When compared to ViT-B, the hybrid VT-ResNet achieved 2.6 points higher accuracy while utilizing 2.5x fewer FLOPs and 2.1x fewer parameters. This suggests that Transformers are indeed most effective in the late stages of a network.

Efficiency in Segmentation

In semantic segmentation, integrating VT into Feature Pyramid Networks (FPN) yielded significant efficiency gains. The VT-FPN achieved better mIoU while reducing the FPN module's compute (FLOPs) by a staggering 6.5x.

Comparison between a standard Feature Pyramid Network (FPN) and the proposed VT-FPN, highlighting the efficiency of the Transformer-based approach.

Conclusion

The Visual Transformer demonstrates that the "Transformer revolution" in vision is most potent when combined with the strengths of convolutions. By focusing on semantic tokens rather than dense pixels, VT models achieve state-of-the-art performance with a fraction of the computational cost. Future work may involve using Neural Architecture Search (NAS) to automatically determine the optimal transition point between convolutional and Transformer layers.

Summary updated

BibTeX
@inproceedings{wu2021visual,
  author = {Bichen Wu and Chenfeng Xu and Xiaoliang Dai and Alvin Wan and Peizhao Zhang and Zhicheng Yan and Masayoshi Tomizuka and Joseph Gonzalez and Kurt Keutzer and Peter Vajda},
  title = {{Visual Transformers: Where Do Transformers Really Belong in Vision Models?}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2021},
  doi = {10.1109/iccv48922.2021.00064},
}
Figure