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 "GPU-Friendly Attention" and a cross-resolution mechanism, it breaks the long-standing dominance of Convolutional Neural Networks (CNNs) in high-speed vision tasks. RTFormer achieves state-of-the-art performance on benchmarks like Cityscapes and CamVid while maintaining exceptionally high frame rates.

What Problem Does This Paper Address?

Semantic segmentation—the task of assigning a category to every pixel in an image—is a cornerstone of autonomous driving and robotics. While Vision Transformers (ViTs) have recently overtaken CNNs in general accuracy due to their ability to capture "global context" (how distant parts of an image relate to each other), they have historically struggled in real-time applications.

The authors identify two main bottlenecks preventing Transformers from running in real-time:

  1. Computational Complexity: Standard self-attention has quadratic complexity relative to image resolution, making high-resolution processing painfully slow.
  2. GPU Inefficiency: The "multi-head" mechanism in standard Transformers splits matrix multiplications into many small groups. On a GPU, this fragmentation is computationally inefficient, much like how "group convolutions" in CNNs often run slower than standard ones despite having fewer theoretical operations.

Methods

To overcome these hurdles, the authors propose RTFormer, which utilizes a dual-resolution design featuring a high-resolution branch for fine details and a low-resolution branch for semantic context.

RTFormer Block Architecture

The core innovations lie within the RTFormer Block:

  • GPU-Friendly Attention (GFA): Derived from "external attention," GFA achieves linear complexity. Crucially, it discards the traditional multi-head mechanism in favor of a single, integrated matrix multiplication that GPUs can process much faster. To keep the representational power of multiple heads, they use a novel Grouped Double Normalization (GDN) to split the normalization step rather than the math itself.
  • Cross-Resolution Attention (CA): Instead of having the high-resolution branch perform expensive self-attention on itself, it "queries" the low-resolution branch. This allows high-resolution pixels to efficiently gather global context from the low-resolution branch's high-level knowledge.
  • Stepped Layout: Unlike previous models that process resolutions in parallel, RTFormer uses a stepped arrangement where the low-resolution branch feeds into the high-resolution branch, ensuring the detailed branch is always "assisted" by global information.
  • Modified FFN: The standard MLP-based Feed-Forward Network is replaced with two $3 \times 3$ convolution layers, which better balances local feature extraction with inference speed.

Key Insights and Ideas

  • Hardware-Aware Design: The biggest takeaway is that theoretical FLOPs (floating-point operations) do not always equate to real-world speed. By making attention "GPU-friendly" (avoiding fragmented matrix operations), the authors achieved better latency even if the underlying math looks similar to other models.
  • Asymmetric Information Exchange: High-resolution pixels focus on local details. They don't need to look at every other high-resolution pixel to understand the scene; they just need a summary. Querying the low-resolution branch provides that summary at a fraction of the computational cost.
  • Hybrid Strength: The model strategically uses CNN blocks in the early stages to learn local textures and saves the Transformer blocks for the final stages where global context matters most.

Key Results

RTFormer sets a new bar for the speed-accuracy trade-off in real-time segmentation tasks.

Accuracy vs. Inference Speed
  • Cityscapes: RTFormer-Slim achieved 76.3% mIoU at 110 FPS on an NVIDIA RTX 2080Ti. The larger RTFormer-Base reached 79.3% mIoU, outperforming established CNN-based real-time models like STDC and DDRNet.
  • CamVid: RTFormer-Slim hit a blistering 190.7 FPS with 81.4% mIoU, significantly outperforming previous state-of-the-art models in both speed and accuracy.
  • Generalization: The model also showed strong results on COCOStuff (35.3% mIoU) and ADE20K (42.1% mIoU), proving its architecture generalizes well beyond driving datasets.

Limitations and Future Work

The authors note that while RTFormer-Slim is highly efficient, it only has 4.8 million parameters. While this is excellent for many applications, specialized edge AI chips might require even more aggressive parameter optimization or different architectural tweaks to reach peak efficiency. They suggest that future work could involve exploring RTFormer designs specifically tailored for low-power mobile NPU (Neural Processing Unit) architectures.

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