Abstract
Semantic segmentation often faces a trade-off between contextual understanding and computational efficiency. ContextFormer addresses this by optimizing the network's bottleneck through a hybrid CNN-Transformer architecture. By integrating a Token Pyramid Extraction Module (TPEM) and a lightweight Trans-BDC block, ContextFormer achieves state-of-the-art accuracy on benchmarks like ADE20K and CityScapes while maintaining ultra-low latency (15ms), making it ideal for real-time applications.
Introduction
Semantic segmentation—assigning category labels to every pixel—is traditionally a struggle between capturing global context and minimizing computational overhead. While Convolutional Neural Networks (CNNs) excel at local feature extraction, they lack the long-range receptive fields of Vision Transformers (ViTs). Conversely, standard ViTs suffer from quadratic complexity relative to image resolution. ContextFormer shifts the focus from encoder optimization to the "bottleneck"—the critical bridge between feature extraction and prediction—to unlock significant efficiency gains.
Methodology
ContextFormer's architecture is built around three core components designed to balance local detail with global semantics without the typical Transformer computational tax.
Token Pyramid Extraction Module (TPEM)
Unlike standard models that rely solely on RGB input, TPEM incorporates gradient magnitude and edge maps to enrich semantic features. It utilizes lightweight MobileNetV2 blocks to generate a multi-scale feature pyramid, preserving spatial details that are often lost in aggressive downsampling.
Trans-BDC Block
The Trans-BDC block serves as the heart of the bottleneck, processing features through two parallel paths:
- Branched DepthwiseConv (BDC): Captures local structures via spatial, cross-channel, and fusion branches.
- Lightweight ViT: A streamlined Transformer branch for global dependencies. Efficiency is achieved through low-dimensional projections and hardware-friendly activations like BatchNorm and ReLU6.
Feature Merging Module (FMM)
FMM employs a gated mechanism to adaptively fuse local pyramid features with global semantics from the bottleneck. This ensures sharp object boundaries and spatial consistency in the final segmentation map.
Experiments and Results
The model was evaluated on major benchmarks including ADE20K, CityScapes, Pascal Context, and COCO-Stuff.
Quantitative Performance
ContextFormer establishes a new Pareto front for efficiency:
- ADE20K: Achieved 35.0% mIoU with only 0.6 GFLOPs and 15ms latency. It significantly outperforms SegFormer-B0 in computational efficiency (14x fewer GFLOPs) while remaining competitive in accuracy.
- CityScapes: Delivered 68.2% mIoU, surpassing TopFormer (66.5%) at an equivalent computational budget.
- Latency: Compared to the CNN-based LR-ASPP, ContextFormer reduced latency by over 70% while improving mIoU by nearly 2%.
Qualitative Insights
Visual results demonstrate that ContextFormer handles intricate objects and boundaries more effectively than previous lightweight models. By explicitly incorporating edge information and maintaining a multi-scale pyramid, the model avoids the loss of fine-grained detail common in models that downscale features excessively.
Conclusion and Future Work
ContextFormer demonstrates that an intelligent bottleneck design can compensate for a lightweight encoder, providing a robust solution for real-time semantic segmentation. Key takeaways include the value of edge-aware feature extraction and the feasibility of high-speed global reasoning via simplified Transformers.
A current limitation is the model's reliance on ImageNet-1K pre-training for optimal performance. Future research will explore reducing this dependency and adapting the architecture for specific edge deployment scenarios, such as mobile robotics and augmented reality.
Summary updated