Vision Transformers for Dense Prediction

René Ranftl, Alexey Bochkovskiy, Vladlen Koltun · DOI

Abstract

Dense prediction tasks, such as monocular depth estimation and semantic segmentation, have traditionally relied on Convolutional Neural Networks (CNNs). However, CNNs are limited by a restricted receptive field and a downsampling bottleneck that discards fine-grained spatial details. We present the Dense Prediction Transformer (DPT), an architecture that replaces the convolutional backbone with a Vision Transformer (ViT). By processing images as a sequence of patches and maintaining a constant resolution throughout the encoder, DPT leverages a global receptive field from the first layer. Our results demonstrate that DPT produces more globally coherent and detailed predictions, achieving a 28% relative improvement in depth estimation over previous state-of-the-art models.

Introduction

Standard dense prediction architectures typically follow an encoder-decoder structure where the encoder is a CNN. While effective, these models progressively reduce the spatial resolution of feature maps to extract high-level semantic information. This downsampling creates a fundamental trade-off: as the receptive field grows to capture context, the spatial precision required for sharp boundaries is lost. Reconstructing these details in the decoder is often insufficient to recover the original granularity.

Furthermore, the receptive field in a CNN grows linearly with depth, meaning that global context is only available in the deepest layers. This can lead to inconsistencies in large-scale structures, such as varying depth estimates for a continuous sky or ground plane.

The Dense Prediction Transformer (DPT)

DPT addresses these limitations by utilizing a transformer-based encoder. Unlike convolutions, the self-attention mechanism in transformers allows every part of the image to interact with every other part at every layer, providing an immediate global receptive field.

Architecture Overview

The DPT architecture consists of three main components: a transformer encoder, a reassemble block, and a convolutional fusion decoder.

The DPT architecture overview, detailing the transformer encoder, the reassemble operation, and the fusion-based decoder.
  1. Transformer Encoder: The input image is divided into patches (tokens). DPT maintains the same number of tokens across all transformer layers, avoiding the aggressive downsampling characteristic of CNNs.
  2. Reassemble Operation: To convert the 1D sequence of tokens back into 2D feature maps suitable for dense prediction, DPT uses a "Reassemble" block. This involves reading the tokens, concatenating them into a spatial grid, and resampling them to multiple resolutions (e.g., 1/4 to 1/32 of the original size) using convolutions.
  3. Fusion Decoder: A series of fusion blocks progressively combine the multi-resolution features from the reassemble blocks to generate a final, high-resolution output.

Experimental Results

DPT was evaluated on several challenging benchmarks for depth estimation and semantic segmentation.

Monocular Depth Estimation

When trained on the massive MIX 6 dataset (1.4 million images), DPT-Large showed a significant leap in performance. In zero-shot cross-dataset transfer tests, it achieved a 28% relative improvement over MiDaS, the previous state-of-the-art CNN-based model.

Qualitative Analysis

The most striking difference between DPT and CNNs is the level of detail in the predictions. As shown in the comparison below, DPT captures fine structures—such as tree branches and complex architectural features—with much greater clarity than MiDaS.

Qualitative comparison of depth estimation. DPT variants produce significantly sharper boundaries and better global coherence compared to the MiDaS baseline.

Key Insights

  • Global Coherence: Because the transformer "sees" the entire image at once, it produces more consistent predictions for large, uniform regions.
  • Granularity: The lack of a downsampling bottleneck allows DPT to preserve high-frequency spatial information, leading to sharper object boundaries.
  • Resolution Robustness: DPT exhibits greater stability when the inference resolution differs from the training resolution, a common failure point for CNNs.

Conclusion

The transition from convolutional backbones to transformers marks a significant shift in dense prediction. DPT demonstrates that global context and high-resolution maintenance are critical for high-quality depth and segmentation maps. While memory consumption remains a challenge for very high resolutions, the parallel nature of transformers ensures competitive inference speeds comparable to modern CNNs.

Summary updated

BibTeX
@inproceedings{ranftl2021vision,
  author = {René Ranftl and Alexey Bochkovskiy and Vladlen Koltun},
  title = {{Vision Transformers for Dense Prediction}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2021},
  doi = {10.1109/iccv48922.2021.01196},
}
Figure