Vision Transformers: From Semantic Segmentation to Dense Prediction

Li Zhang, Jiachen Lu, Sixiao Zheng, Xinxuan Zhao, Xiatian Zhu, Yanwei Fu, Tao Xiang, Jianfeng Feng, Philip H. S. Torr · DOI

TL;DR

This paper expands the power of Vision Transformers (ViTs) from image classification to dense prediction tasks like semantic segmentation and object detection. By rethinking the traditional Fully Convolutional Network (FCN) design, the authors introduce SETR, which leverages a pure transformer encoder to maintain a full receptive field at every layer, and HLG Transformers, a hierarchical variant that efficiently blends local and global attention to deliver state-of-the-art dense predictions.

What Problem Does This Paper Address?

For years, Fully Convolutional Networks (FCNs) have dominated dense prediction tasks like semantic segmentation. However, FCNs suffer from an intrinsic limitation: their receptive fields grow slowly and linearly layer by layer. To capture the long-range context necessary to understand complex scenes, researchers have relied on remedies like dilated convolutions, large kernels, and multi-scale feature pyramids.

While vanilla Vision Transformers (ViTs) naturally solve this by modeling global context right from the first layer, they aren't a perfect drop-in replacement for all dense prediction tasks. Standard ViTs lack a pyramidal structure (crucial for multi-scale object detection), struggle with fine-grained local context processing, and suffer from high computational demands when processing high-resolution images. This paper tackles these challenges head-on.

Methods

The authors propose two primary architectures:

1. SEgmentation TRansformer (SETR)

Instead of progressively downsampling feature maps like a standard FCN, SETR treats semantic segmentation as a sequence-to-sequence learning problem.

  • Encoder: An image is decomposed into a grid of fixed-sized patches, flattened, linearly embedded, and combined with positional embeddings. This sequence is fed into a standard ViT encoder that maintains the same spatial resolution throughout.
  • Decoders: To project these features back to the original image resolution, the authors introduce three decoder designs: Naive upsampling, Progressive UPsampling (PUP), and Multi-Level feature Aggregation (MLA).
Local-Global attention mechanism

2. Hierarchical Local-Global (HLG) Transformers

To extend ViTs cost-effectively to broader dense prediction tasks (like object detection and instance segmentation), the authors introduce a pyramidal architecture consisting of four stages.

Local-Global attention mechanism

The core innovation is the HLG Transformer layer, which elegantly balances efficiency and context:

  • Local Attention: Self-attention is computed within non-overlapping local windows. To capture longer-range dependencies without extra computational cost, they alternate this with a dilated local attention mechanism.
  • Global Attention: A compact global feature map is generated via window embedding (e.g., average pooling). Global context is then modeled efficiently by querying the local features against this downsampled global map.
  • Parameter & Computation Sharing: To maximize efficiency, the parameters and initial projection computations are shared between the local and global attention mechanisms.
Local-Global attention mechanism

Datasets

The architectures were evaluated across several competitive benchmarks:

  • Semantic Segmentation: ADE20K (150 fine-grained categories), Cityscapes (urban scenes), and Pascal Context.
  • Image Classification: ImageNet-1K (1.28 million training images).
  • Object Detection & Instance Segmentation: COCO 2017 (118K training images).

Key Insights and Ideas

  • Rethinking the Resolution Pyramid: For semantic segmentation, a resolution pyramid isn't strictly necessary in the encoder. SETR proves that maintaining a constant spatial resolution combined with global self-attention at every layer yields superior feature representations.
  • Dilated Windows for Transformers: Just as dilated convolutions expanded the receptive fields of CNNs, applying dilation to local attention windows allows transformers to discover longer-range dependencies without increasing computational complexity.
  • Synergistic Attention Sharing: By mathematically aligning the local and global attention formulations, the authors show that global queries can reuse local projection outputs, reducing the computational overhead typically associated with dual-attention mechanisms.

Key Results

  • ADE20K Leaderboard Success: SETR achieved a state-of-the-art 50.28% mIoU on the ADE20K validation set, securing first place on the highly competitive test server leaderboard on its submission day. Boosted with BEiT pre-training, it reached 53.1% mIoU.
  • Strong Segmentation Visuals: Qualitative evaluations show that SETR and HLG generate much cleaner, more precise boundaries for small object instances and complex structures compared to dilated FCN baselines.
Qualitative results on Cityscapes: SETR vs. dilated FCN baseline
  • Object Detection & Classification: The HLG-Large backbone achieved an impressive 84.1% Top-1 accuracy on ImageNet-1K. When deployed in a RetinaNet framework on COCO, HLG-Tiny outperformed ResNet-18 by 11.5% AP and PVT-T by 6.6% AP while maintaining a highly competitive parameter count.

Limitations and Future Work

Despite the architectural optimizations introduced with HLG, vanilla single-stage ViTs (like SETR) still suffer from high computational and pre-training costs, showing a heavy reliance on large-scale pre-training data (like ImageNet-21K) to reach peak performance.

The authors note that as high-performance computation hardware and training techniques continue to evolve, further optimizing the cost-to-performance ratio of these transformer backbones remains an important direction for future research.

Summary updated

BibTeX
@article{zhang2024vision,
  author = {Li Zhang and Jiachen Lu and Sixiao Zheng and Xinxuan Zhao and Xiatian Zhu and Yanwei Fu and Tao Xiang and Jianfeng Feng and Philip H. S. Torr},
  title = {{Vision Transformers: From Semantic Segmentation to Dense Prediction}},
  journal = {Int. J. Comput. Vis.},
  year = {2024},
  url = {https://openreview.net/forum?id=yJhInOn4ZR},
}
Figure