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

Abstract

The emergence of vision transformers (ViTs) in image classification has shifted the methodologies for visual representation learning. In particular, ViTs learn visual representation at full receptive field per layer across all the image patches, in comparison to the increasing receptive fields of CNNs across layers and other alternatives. In this work, for the first time we explore the global context learning potentials of ViTs for dense visual prediction (e.g., semantic segmentation). Our motivation is that through learning global context at full receptive field layer by layer, ViTs may capture stronger long-range dependency information, critical for dense prediction tasks. We first demonstrate that encoding an image as a sequence of patches, a vanilla ViT without local convolution and resolution reduction can yield stronger visual representation for semantic segmentation. Our model, termed as SEgmentation TRansformer (SETR), excels on ADE20K (50.28% mIoU) and performs competitively on Cityscapes. However, the basic ViT architecture falls short in broader dense prediction applications due to its lack of a pyramidal structure and high computational demand. For tackling general dense visual prediction tasks in a cost-effective manner, we further formulate a family of Hierarchical Local-Global (HLG) Transformers, characterized by local attention within windows and global-attention across windows in a pyramidal architecture. Extensive experiments show that our methods achieve appealing performance on a variety of dense prediction tasks as well as image classification.

Introduction

For years, Fully Convolutional Networks (FCNs) dominated dense prediction tasks. However, CNNs possess an inherent limitation: their receptive field grows incrementally layer by layer. To capture global context, researchers traditionally relied on auxiliary techniques like dilated convolutions or image pyramids. Vision Transformers (ViTs) offer a paradigm shift by utilizing self-attention to model global dependencies from the very first layer. This work explores the potential of ViTs for dense visual prediction, introducing SETR for semantic segmentation and HLG Transformers for general dense prediction tasks.

The SETR Framework

The SEgmentation TRansformer (SETR) treats image segmentation as a sequence-to-sequence problem. Instead of the standard encoder-decoder CNN architecture, SETR decomposes an image into a sequence of patches. A "pure" Transformer encoder then processes these patches, maintaining a constant resolution and providing a global receptive field at every layer.

To transform the sequence output back into a 2D segmentation map, three decoder variants were developed:

  1. Naive: Simple bilinear upsampling.
  2. Progressive UpSampling (PUP): A series of upsampling steps to minimize noise.
  3. Multi-Level feature Aggregation (MLA): Aggregates features from different layers to capture multi-scale information.
Overview of the SETR architecture and its decoder variants (PUP and MLA).

Hierarchical Local-Global (HLG) Transformers

While SETR excels in segmentation, its lack of a pyramidal structure and high computational cost limit its use in broader tasks like object detection. To address this, we introduce Hierarchical Local-Global (HLG) Transformers. HLG adopts a four-stage pyramidal architecture similar to CNNs, allowing it to handle multi-scale features efficiently.

The core of this architecture is the HLG layer, which balances local detail with global context. It utilizes Local Attention within small windows and Global Attention across windows. To expand the field of view without increasing computational overhead, the model employs "dilated local attention."

Illustration of dilated local attention used in HLG Transformers.

Experimental Results

The proposed models were evaluated on major benchmarks including ADE20K, Cityscapes, and COCO.

  • Semantic Segmentation: SETR achieved a state-of-the-art 50.28% mIoU on the ADE20K test leaderboard.
  • Image Classification: HLG-Large reached 84.1% Top-1 accuracy on ImageNet-1K, outperforming comparable Swin and ConvNext models.
  • Object Detection: On COCO, HLG-Tiny surpassed ResNet-18 by 11.5% AP, demonstrating the effectiveness of the hierarchical transformer backbone for dense prediction.

Conclusion

This research demonstrates that Vision Transformers can be effectively adapted for dense prediction by leveraging global context and hierarchical structures. By moving beyond the spatial constraints of convolutions, SETR and HLG Transformers set new benchmarks for accuracy and efficiency in computer vision.

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