Computer Vision Lab Models SegFormer
SegFormer
Hierarchical transformer encoder + MLP decoder
Knowledge card: semantic segmentation with a hierarchical transformer. Not loaded because the licence of the official weights does not allow distribution.
| Architecture | Hierarchical transformer encoder + MLP decoder |
|---|---|
| Task | Segmentation |
| Training data | ADE20K / Cityscapes |
| the number of parameters | B0: ≈3.8M |
| Framework | PyTorch |
| File size | — |
| Licence | Check the licence of the official weights (NVIDIA) |
| Where it runs | Knowledge card only |
| Official source | doi.org |
Architecture diagram
- Input / output
- Convolutional layer
- Attention / transformer
- Output head
- Operation (add, multiply, merge)
Detailed model explanation
Idea and intuition
SegFormer combines a hierarchical transformer encoder with a very simple decoder made only of MLP layers. The paper argues that the hierarchical transformer produces strong multi-scale features with wide receptive fields, so no complex decoder is needed. The encoder also abandoned the fixed positional encoding, replacing it with a 3×3 depthwise convolution inside the FFN layer (Mix-FFN) that provides position information implicitly, so the model works at test resolutions that differ from the training resolution without degradation.
The Mix Transformer (MiT) encoder
- Four stages at resolutions 1/4, 1/8, 1/16 and 1/32.
- Overlapped patch merging (overlapped patch merging) with a strided convolution, to preserve local continuity.
- Efficient self-attention: the sequence length of the keys and values is reduced by a ratio
Rso the cost falls fromO(N^2)intoO(N^2/R). - Mix-FFN:
x_{out}=\mathrm{MLP}(\mathrm{GELU}(\mathrm{DWConv}_{3\times3}(\mathrm{MLP}(x_{in}))))+x_{in}.
The All-MLP decoder
- Unify the channels of the four feature maps with a linear layer.
- Upsample them all to 1/4 resolution and concatenate them.
- A linear layer for fusion, then a linear layer for classification.
Mathematical formulation
\hat K = \mathrm{Linear}(C\cdot R, C)\big(\mathrm{Reshape}(N/R,\ C\cdot R)(K)\big)Strengths and limitations
- Strength: an excellent balance between accuracy and size; the smallest version (B0) has about 3.8 million parameters.
- Strength: robustness to resolution changes and image corruptions, according to the paper's experiments on Cityscapes-C.
- Limitation: the licence of NVIDIA's official weights does not allow redistribution here, so it is a knowledge card only.
- Limitation: attention is still costly on very large images.
Uses
Semantic segmentation.
Runtime requirements
—
How to load
Not loaded.
References
- E. Xie et al. (2021).SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers. arXiv:2105.15203 (NeurIPS 2021). doi:10.48550/arXiv.2105.15203
