Segmenter: Transformer for Semantic Segmentation
- Publication
- ICCV 2021Conference
- First submitted to arXiv
- arXiv:2105.05633
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{segmentationsegmenter2021,
title = {{Segmenter: Transformer for Semantic Segmentation}},
author = {Robin Strudel and Ricardo Garcia and Ivan Laptev and Cordelia Schmid},
year = {2021},
eprint = {2105.05633},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2105.05633}
}
SETR had already shown that ViT, used unchanged as the encoder of a segmentation network, can work very well. But its decoder was still convolutional: progressive upsampling or multi-level aggregation, either way it was a pile of convolution layers bolted onto the Transformer.
Robin Strudel, Ricardo Garcia, Ivan Laptev and Cordelia Schmid of Inria and the École normale supérieure in Paris wanted to go one step further and build the decoder with a Transformer too. Their approach borrows DETR's queries: prepare a learnable vector for each class, pass it through the Transformer together with the image patches, and finally get each class's mask with a dot product.
The paper also runs a systematic round of ablations, measuring one by one how model size, patch size, regularization and data volume each affect ViT when it's used for segmentation.
Defining the Problem
The locality of convolution limits its ability to see global context, and segmentation often depends precisely on global context to tell what a small region is. DeepLab enlarges the receptive field with atrous convolution and pyramid pooling, while DANet and OCRNet add various attention modules. The authors argue that the heavy use of these specially designed layers as patches is itself a sign of the limits of convolutional architectures for segmentation.
A Transformer sees the entire input from the first layer and has no built-in preference for locality. But its computation is proportional to the square of the sequence length, so you can't make every pixel a token. Segmenter therefore follows ViT and cuts the image into patches.
What remains is the decoder. The encoder outputs one vector per patch; how do you turn that into one class per pixel? The simplest way is to attach a linear layer directly, projecting each patch vector into scores for classes and then upscaling to the original image. The authors use this as the baseline first, then propose a mask decoder built around a Transformer.
Solving the Problem
Architecture

The encoder in the left half is just ViT. The image is cut into patches, in all; each patch is flattened, linearly projected to dimensions, given a learnable position embedding and fed into Transformer layers. The authors use four sizes of ViT:
| Name | Layers | Dim | Heads | Params |
|---|---|---|---|---|
| Seg-Ti | 12 | 192 | 3 | 6M |
| Seg-S | 12 | 384 | 6 | 22M |
| Seg-B | 12 | 768 | 12 | 86M |
| Seg-L | 24 | 1024 | 16 | 307M |
There are three patch sizes, 8, 16 and 32, and models are named "size/patch", for example Seg-B/16.
Let's walk through the ADE20K setting: 512×512 training crops with Seg-B/16. Each side is cut into 32 pieces, so patches, and the encoder outputs a sequence.
Linear Decoder
The baseline is simple. A linear layer is applied to each patch's 768-dimensional vector, outputting scores for ADE20K's 150 classes to give ; this is reshaped to , bilinearly upscaled to , and passed through a softmax over classes.
Mask Transformer
Segmenter's headline decoder adds one more set of vectors: learnable class embeddings, each -dimensional, randomly initialized and each permanently assigned to one class. ADE20K has 150 classes, so there are 150 of them.
These 150 class embeddings are joined to the 1,024 patch encodings to form 1,174 tokens, which go together into an -layer Transformer (the experiments use , with the same dimension as the encoder). In these two layers, the class embeddings and the patches exchange information through self-attention: the class embeddings see which patches in this image look like them, and the patches see which classes are present.
At the output, the patch vectors () and the class vectors () are each L2-normalized, and then their dot products are taken:
This gives , where each column is one class's mask and each row is one patch's scores for the 150 classes. The remaining steps are the same as in the linear version: reshape, upscale, softmax over classes, and finally one more LayerNorm. Because the softmax runs across classes, each pixel's 150 scores sum to 1, and the authors describe these masks as "softly exclusive" of each other.
The authors say the design was inspired by DETR, Max-DeepLab and SOLOv2. The biggest difference from the linear decoder is that the class vectors change with the input image. A linear layer's weights are fixed, the same set for every image; after two Transformer layers, the class embeddings have absorbed information from this image, so every image effectively gets its own set of dynamic filters.
The difference from Max-DeepLab is that Max-DeepLab is a hybrid of CNN and Transformer that processes pixels and classes in two separate streams; Segmenter is a pure Transformer that processes patches and classes together in one sequence. The authors also mention that replacing the class embeddings with object embeddings would let the same architecture do panoptic segmentation.
Discussion
Training Setup
There are two choices of pretrained ViT weights. The original ViT on ImageNet-21K used only random cropping; later, Steiner et al. (AugReg) retrained it with dropout, stochastic depth, Mixup and RandAugment, gaining about 2 points of ImageNet accuracy. The authors fine-tuned Seg-B/16 on ADE20K from both sets of weights and got 45.69 and 48.06 respectively, so from then on they use the AugReg version throughout.
Data augmentation follows the standard MMSegmentation pipeline, with crops of 512 for ADE20K, 480 for Pascal Context and 768 for Cityscapes. The optimizer is SGD with weight decay set to 0, and the loss is unweighted per-pixel cross-entropy.
Regularization
CNNs get regularization on the side from BatchNorm; Transformers usually use LayerNorm plus dropout. On Seg-S/16, the authors compared combinations of dropout and stochastic depth (randomly skipping whole blocks):
| stochastic depth 0 | 0.1 | 0.2 | |
|---|---|---|---|
| dropout 0 | 45.01 | 45.37 | 45.10 |
| dropout 0.1 | 42.02 | 42.30 | 41.14 |
| dropout 0.2 | 36.49 | 36.63 | 35.67 |
(From Table 2 of the paper, ADE20K validation set.)
Stochastic depth of 0.1 helps a little, and dropout only hurts. Adding 0.2 dropout costs nearly 9 points. From then on, every model uses stochastic depth 0.1 and no dropout.
Model Size and Patch Size
Results on the ADE20K validation set (Table 3 of the paper, linear decoder, single scale; speed measured on a V100 at 512 resolution with the largest batch memory allows):
| Model | Patch | Images/s | mIoU |
|---|---|---|---|
| Seg-Ti/16 | 16 | 396 | 39.03 |
| Seg-S/32 | 32 | 1,032 | 40.64 |
| Seg-S/16 | 16 | 196 | 45.37 |
| Seg-B/32 | 32 | 516 | 43.07 |
| Seg-B/16 | 16 | 92 | 48.06 |
| Seg-B/8 | 8 | 7 | 49.54 |
| Seg-L/16 | 16 | 33 | 50.71 |
As the model grows, the score rises steadily: doubling the token dimension (S → B) adds 2.69, and doubling the layers (B → L) adds 2.65. The largest, Seg-L/16, gets 50.71 decoding with just one linear layer.
Patch size matters as much as model size. Seg-B going from 32 to 16 gains 5 points; going on to 8 reaches 49.54, only 1.17 below Seg-L/16 with far fewer parameters. But patch 8 gives a sequence four times as long as patch 16, with sixteen times the attention computation, and speed falls from 92 images per second to 7. The authors say that, if the computation were affordable, ViT-L/8 might be the best model.

At patch 32, the two people on the left are predicted as one solid blob; at patch 16 the boundary is much clearer; the thin lamppost is caught only at patch 8.
Broken Down by Object Size
The authors break mIoU down by object size and compare it with the convolutional DeepLabv3+ (ResNeSt-101) (Table 4 of the paper):
| Model | Decoder | Small | Medium | Large | Overall |
|---|---|---|---|---|---|
| DeepLabv3+ | UNet | 37.85 | 50.89 | 50.67 | 46.47 |
| Seg-B/16 | Linear | 39.57 | 51.32 | 53.28 | 48.06 |
| Seg-B/16 | Mask | 40.16 | 52.61 | 52.66 | 48.48 |
| Seg-B/8 | Linear | 41.43 | 54.35 | 52.85 | 49.54 |
| Seg-L/16 | Linear | 42.08 | 54.67 | 55.39 | 50.71 |
| Seg-L/16 | Mask | 42.02 | 54.83 | 57.06 | 51.30 |
The biggest gap between Segmenter and DeepLab is on large objects, where Seg-L with the mask decoder leads by 6.39, which the authors credit to the Transformer's grasp of global context. On small and medium objects, Seg-B/16, with a similar parameter count, is about level with DeepLab.
The mask decoder is consistently better than the linear decoder: 1.6 more for Seg-B†/16 (DeiT), 1.1 more for Seg-B/32 and 0.6 more for Seg-L/16, with most of the gain coming from large objects. The authors also analyze the learned class embeddings and find that similar classes sit close together in the vector space.
Data Volume
ViT is known for needing a lot of data. The authors fine-tuned Seg-S/16 on only part of the ADE20K training set: 4,000 images give 38.31, 8,000 give 41.87, and the full 20,000 give 45.37. Below 8,000 images the drop is especially steep, so even for fine-tuning, a Transformer needs enough data.
Speed and Accuracy

The horizontal axis is images processed per second (log scale) and the vertical axis is mIoU; further up and to the right is better. The patch-16 Segmenter (red line) lies entirely above and to the right of DeepLabV3+ (green line). The authors single out Seg-B-Mask/16, which matches SETR-MLA at twice the speed and with fewer parameters; the patch-32 Seg-B-Mask/32 runs at 400 images per second, four times faster than the ResNet-50 DeepLab, with about the same score.
Against Other Methods
On the ADE20K validation set (Table 6 of the paper, multi-scale testing), the largest model, Seg-L-Mask/16, gets 53.63, 5.27 above DeepLabv3+ ResNeSt-200 (48.36), also better than SETR-MLA (50.28) and on par with Swin-L UperNet (53.50). Seg-B†-Mask/16 (DeiT), pretrained only on ImageNet-1K, still gets 50.08, beating every convolutional method.
On Pascal Context, Seg-L-Mask/16 gets 59.0, 2.8 above OCRNet (HRNet) and 3.2 above SETR-MLA.
Cityscapes is a different story. Seg-L-Mask/16 gets 81.3, below DeepLabv3+ ResNeSt-200's 82.7 and SETR-PUP's 82.2. The authors mention that Cityscapes' 768×768 input is so large that the mask decoder fits only one layer. Another possible reason (our guess) is that Cityscapes images are high-resolution and full of small, thin objects, and at patch 16 the model works at only 1/16 resolution, which puts it at a disadvantage here.
Conclusion
Segmenter replaces both ends of the segmentation network with Transformers. The encoder is ViT, and the decoder passes a set of class embeddings through two Transformer layers together with the patches, then computes each class's mask with a dot product. On ADE20K and Pascal Context it was the best method of its time, and its scores keep climbing with smaller patches or bigger models.
Its ablations are more practical than the method itself. If you want to use ViT for segmentation, this paper has already done the measuring for you. Use an enhanced pretrained version like AugReg, regularize with stochastic depth and not dropout, treat patch size as seriously as model size, and brace yourself when you have fewer than a few thousand images.
The structure of "one query per class, with query–pixel dot products giving masks" became "one query per region" in MaskFormer two months later, no longer tied to a class, so the same model could also do instance and panoptic segmentation. A few years after that, EoMT simply stuffed the queries straight into the last few layers of ViT, removing the separate decoder altogether.