RTFormer: Efficient Design for Real-Time Semantic Segmentation with Transformer

Jian Wang, Chenhui Gou, Qiman Wu, Haocheng Feng, Junyu Han, Errui Ding, Jingdong Wang

TL;DR

RTFormer is a novel dual-resolution transformer architecture designed specifically for real-time semantic segmentation. By introducing a GPU-Friendly Attention mechanism with linear complexity and a cross-resolution attention strategy, it breaks the latency barriers that typically restrict vision transformers to offline tasks, achieving state-of-the-art trade-offs between speed and accuracy.

What Problem Does This Paper Address?

Semantic segmentation—the task of assigning a semantic label to every pixel in an image—is crucial for real-time applications like autonomous driving and robotics. While Vision Transformers (ViTs) have recently dominated general semantic segmentation due to their ability to capture long-range context, real-time applications are still heavily dominated by Convolutional Neural Networks (CNNs).

The authors identify two primary bottlenecks preventing transformers from going real-time:

  1. GPU-Unfriendly Attention Mechanisms: Standard self-attention suffers from quadratic computational complexity relative to image resolution. Even linear-complexity alternatives often rely on a "multi-head" mechanism. Multi-head attention splits matrix multiplications into small, fragmented groups (similar to group convolutions), which introduces significant overhead on GPU-like hardware.
  2. Inefficient Context Gathering: Performing self-attention directly on high-resolution feature maps is computationally expensive and inefficient for capturing high-level semantic context, as individual high-resolution pixels have limited receptive fields early on.

Methods

To solve these issues, the authors propose RTFormer, which combines CNN blocks in the early stages with a specialized dual-resolution transformer layout in the final stages.

The core innovation lies in the RTFormer block, which processes high- and low-resolution features in a stepped layout:

Figure 2: Illustration of RTFormer block. For low resolution, GPU-Friendly Attention is applied. And for high resolution, we use Cross-resolution Attention which draws K and V from low resolution branch. Besides, we make up FFN with two 3 × 3 convolution layers.
  • GPU-Friendly Attention (GFA): Used in the low-resolution branch, GFA is derived from external attention. To make it hardware-friendly, it discards the multi-head channel split, allowing matrix multiplications to remain fully integrated. To prevent a drop in model capacity, it introduces Grouped Double Normalization (GDN), which splits only the normalization operation into groups rather than the matrix multiplication itself.
  • Cross-Resolution Attention (CA): Instead of computing expensive self-attention on the high-resolution branch, RTFormer uses cross-attention. Here, the high-resolution features serve as the Query ($Q$), while the Keys ($K$) and Values ($V$) are derived from the low-resolution branch. This allows high-level global context from the low-resolution branch to be efficiently broadcast to the high-resolution pixels.
Figure 3: Comparison between Multi-Head Exter- nal Attention and GPU-Friendly Attention. Multi- head external attention splits the matrix multiplica- tion into several groups while our GPU-Friendly Attention makes matrix multiplication to be inte- grated which is more friendly for GPU-like de- vices.
  • Custom Feed-Forward Network (FFN): Instead of the standard MLP and depth-wise convolution setup that expands hidden dimensions, RTFormer uses two simple $3 \times 3$ convolution layers without dimension expansion, further reducing GPU latency.

Datasets

The authors evaluated RTFormer on four popular semantic segmentation benchmarks:

  • Cityscapes: Urban street scenes (19 classes, fine-annotated images split into 2,975 train, 500 val, and 1,525 test).
  • CamVid: Automotive driving scenes (11 semantic classes, 701 densely annotated frames).
  • COCOStuff: A challenging, diverse dataset covering 182 categories (10K images split into 9K for training and 1K for testing).
  • ADE20K: A scene parsing dataset covering 150 fine-grained concepts (20K training, 2K validation images).

All models were pretrained on ImageNet-1K before fine-tuning.

Key Insights and Ideas

  • Integrated Math is Faster Than Fragmented Math: The multi-head mechanism in traditional transformers is conceptually elegant but practically slow on GPUs. Keeping matrix multiplications large and integrated (as in GFA) leverages GPU parallelization much better than splitting them into multiple heads.
  • Stepped Layout Over Parallel Fusion: Rather than processing resolutions independently and fusing them at the end, arranging the branches so that the low-resolution branch directly feeds into the high-resolution branch via cross-attention allows for much more effective feature enhancement.
  • High-Res Doesn't Need Self-Attention: High-resolution branches excel at spatial detail but struggle with global context. Using cross-resolution attention allows the high-res branch to "borrow" global context from the low-res branch without paying the quadratic computational tax of high-res self-attention.

Key Results

RTFormer was evaluated in two variants: RTFormer-Slim (4.8M parameters) and RTFormer-Base (16.8M parameters). It achieved state-of-the-art real-time performance across multiple datasets:

Figure 1: Accuracy(mIoU%) vs. Infer- ence Speed(FPS) on CamVid[4] test set. Our methods are presented in red dots while other methods are presented in blue dots.
  • CamVid: RTFormer-Slim achieved 81.4% mIoU at 190.7 FPS, while RTFormer-Base reached 82.5% mIoU at 94.0 FPS, significantly outperforming previous CNN-based methods like STDC and DDRNet.
  • Cityscapes: RTFormer-Slim achieved 76.3% mIoU at 110.0 FPS, outperforming DDRNet-23-Slim in both speed and accuracy. RTFormer-Base achieved 79.3% mIoU at 39.1 FPS.
  • COCOStuff: RTFormer-Base reached 35.3% mIoU at 143.3 FPS, outperforming DDRNet-23 by about 3% mIoU at a comparable speed.
  • ADE20K: RTFormer-Base achieved a superior real-time mIoU of 42.1% at 71.4 FPS.

Limitations and Future Work

The authors note one primary limitation: while RTFormer-Slim is highly efficient with only 4.8M parameters, deploying it on ultra-low-power edge device chips may require even greater parameter efficiency. The authors leave the optimization of RTFormer for specific edge hardware architectures as a direction for future work.

Summary updated

BibTeX
@inproceedings{wang2022rtformer,
  author = {Jian Wang and Chenhui Gou and Qiman Wu and Haocheng Feng and Junyu Han and Errui Ding and Jingdong Wang},
  title = {{RTFormer: Efficient Design for Real-Time Semantic Segmentation with Transformer}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=FikzWLo2AaO},
}
Figure