Transformer Scale Gate for Semantic Segmentation

Hengcan Shi, Munawar Hayat, Jianfei Cai

Abstract

Semantic segmentation requires capturing objects across a wide range of scales. While hierarchical Vision Transformers (ViTs) provide multi-scale features, standard fusion methods often introduce noise by failing to select the optimal scale for specific image patches. We present the Transformer Scale Gate (TSG), a lightweight, plug-and-play module that repurposes inherent self- and cross-attention maps as "scale guides." By dynamically weighting feature scales per patch, TSG achieves significant performance gains—up to 4.3% mIoU on Pascal Context—without the heavy computational overhead of traditional multi-scale fusion methods.

What Problem Does This Paper Address?

Semantic segmentation—the task of assigning a category label to every pixel in an image—is notoriously difficult because objects appear at vastly different sizes. A tiny bird in the distance requires high-resolution (large-scale) features to capture its fine details, while a massive building requires low-resolution (small-scale) features with a wide "receptive field" to understand its overall structure.

Current state-of-the-art models use hierarchical Vision Transformers (like Swin or PVT) to extract features at multiple scales. However, they typically combine these scales using simple methods like addition or concatenation (e.g., Feature Pyramid Networks). The authors argue that this "one-size-fits-all" approach is sub-optimal: including features from the wrong scale for a specific patch can actually introduce noise and degrade segmentation accuracy.

Methods

The core innovation is the Transformer Scale Gate (TSG). Instead of building a complex new sub-network to decide which scale to use, the authors look at the attention maps already being calculated by the Transformer:

  1. Self-Attention Guidance (Encoder): If an image patch is highly correlated with many other patches (dense self-attention), it likely belongs to a large, uniform object. In this case, the TSG prefers small-scale (low-resolution) features because they have a larger effective receptive field.
  2. Cross-Attention Guidance (Decoder): In the decoder, patches are compared against object queries. If a patch correlates with many different object queries, it likely contains multiple small objects or complex boundaries. Here, the TSG prefers large-scale (high-resolution) features for fine-grained detail.

The authors implement this through two specific modules:

TSGE (Encoder)

The TSGE module gradually fuses small-scale features into larger ones during the encoding process, weighted by gates derived from self-attention.

TSGE Architecture: Multi-scale feature fusion in the encoder guided by self-attention gates.

TSGD (Decoder)

The TSGD module fuses multi-scale features in each decoder block, weighted by gates derived from cross-attention.

TSGD Architecture: Multi-scale feature fusion in the decoder guided by cross-attention gates.

Key Results

The TSG module provided consistent improvements over the Swin Transformer baseline across two primary benchmarks: Pascal Context (60 categories) and ADE20K (150 categories).

  • Pascal Context: Achieved a +4.3% mIoU gain with Swin-Tiny and +3.0% with Swin-Large.
  • ADE20K: Achieved a +3.1% mIoU gain with Swin-Tiny.
  • State-of-the-Art Comparison: The method outperformed other specialized architectures like SenFormer and MaskFormer, while often using significantly fewer parameters (e.g., 250M params vs. SenFormer's 314M for the Large backbone).
  • Qualitative Success: Visualizations show that TSG successfully segments small objects (like a distant person) and maintains sharper boundaries for sidewalks and roads where traditional models often "over-segment" or blur the edges.

Key Insights and Ideas

  • Attention as a Proxy for Scale: The most elegant "aha" moment is realizing that attention maps are essentially a free "importance map" for scale. A patch that "looks" at everything (global attention) needs a global scale; a patch that "looks" at specific queries needs a local, detailed scale.
  • Plug-and-Play Efficiency: Because TSG uses existing attention maps and only adds a few lightweight linear layers, it is much more efficient than previous CNN-based scale selection methods that required multiple networks or extra "scale labels" for training.
  • Dynamic Weighting: Unlike static fusion (like FPN), TSG provides a unique weight for every single patch at every scale, allowing the model to be highly surgical in how it uses its feature memory.

Limitations and Future Work

While TSG effectively handles scale, the authors noted that the model still struggles with semantic ambiguity. For example, it can still confuse objects with very similar textures, such as "wood" vs. a "wooden wall" or "building."

The authors suggest that while TSG optimizes where the model looks (scale), future work could focus on more discriminative features to better distinguish between visually similar categories. Additionally, while the module is "plug-and-play," its current implementation is optimized for hierarchical Transformers; adapting it for non-hierarchical (plain) ViTs remains an open area for exploration.

Summary updated

BibTeX
@inproceedings{shi2022transformer,
  author = {Hengcan Shi and Munawar Hayat and Jianfei Cai},
  title = {{Transformer Scale Gate for Semantic Segmentation}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2022},
}
Figure