SegNeXt: Rethinking Convolutional Attention Design for Semantic Segmentation
- Publication
- NeurIPS 2022Conference
- First submitted to arXiv
- arXiv:2209.08575
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{segmentationsegnext2022,
title = {{SegNeXt: Rethinking Convolutional Attention Design for Semantic Segmentation}},
author = {Meng-Hao Guo and Cheng-Ze Lu and Qibin Hou and Zhengning Liu and Ming-Ming Cheng and Shi-Min Hu},
year = {2022},
eprint = {2209.08575},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2209.08575}
}
In 2022 the semantic segmentation leaderboards were almost all Transformers. With SETR, SegFormer, MaskFormer and Mask2Former on top, everyone took it for granted that self-attention beats convolution, because a single layer can see the whole image.
Meng-Hao Guo of Tsinghua University, Ming-Ming Cheng of Nankai University and their colleagues weren't so sure. Guo had earlier built VAN (Visual Attention Network), which mimics attention with large convolution kernels and had already matched Transformers on ImageNet classification. SegNeXt applies the same idea to segmentation, arguing that convolutional attention suits segmentation better than self-attention and costs far less.
The result is an almost entirely convolutional model that beat the best methods of the time on six datasets, including ADE20K, Cityscapes and COCO-Stuff.
Defining the Problem
Rather than directly asking "which is better, convolution or the Transformer," the authors first look back at successful segmentation models and list the properties they share:
- A strong encoder. The authors believe most of the progress of Transformer methods comes from stronger backbones rather than from the Transformer structure itself.
- Multi-scale interaction. Classification usually only needs to recognize one main object; segmentation has to handle things of every size in one image at the same time.
- Spatial attention. It tells the model which positions within a semantic region to focus on.
- Low computational complexity. For high-resolution images like street scenes and remote sensing, compute is a real constraint.
The authors check earlier models against these four points in a table. DeepLabV3+ and HRNet have multi-scale interaction and compute that's linear in the number of pixels, but no strong encoder and no spatial attention. SETR and SegFormer have strong encoders and attention, but the authors consider them lacking in multi-scale interaction, and the cost of their self-attention grows with the square of the number of pixels. SegFormer does use spatial reduction to lower the cost of attention, yet on 2048×1024 Cityscapes images the B2 version still needs 717G FLOPs.
So the authors ask whether cheap convolutions can deliver all four at once.
Solving the Problem
Multi-Scale Convolutional Attention (MSCA)

SegNeXt's encoder is called MSCAN, and its overall structure follows ViT. Each block is "normalization, attention, normalization, FFN," except that self-attention is replaced by the authors' own MSCA (multi-scale convolutional attention).
Look at (b) on the right. MSCA has three parts:
- A 5×5 depth-wise convolution that aggregates local information.
- Three multi-scale branches that capture context over different ranges.
- A 1×1 convolution that mixes information across channels.
The output of the 1×1 convolution is used directly as attention weights and multiplied element-wise with MSCA's input:
is the identity connection, and through are the three branches.
Run a 512×512 ADE20K image through SegNeXt-T, and the third-stage features are 32×32×160. After the 5×5 depth-wise convolution they're still 32×32×160. The three branches each output a 32×32×160 copy, which with the identity connection makes four, and these are summed; the 1×1 convolution remixes the 160 channels into a weight map Att, also 32×32×160; finally Att is multiplied element-wise with the input . Nowhere in the process is there a "pixel-to-pixel" matrix, and compute is linear in the number of pixels.
This "attention" is different from Transformer self-attention. It doesn't compute pairwise similarities between pixels; instead it uses convolutions to compute a weight map the same size as the input, which amplifies or suppresses the original features pixel by pixel and channel by channel. The weight map is computed from the input, so it changes with the input, which is why it gets called "attention."
Why Strip Convolutions
The three branches have receptive fields of 7×7, 11×11 and 21×21, but none of them uses a square kernel. Each is a pair of long, thin strip convolutions, first and then .
As for the savings, a 21×21 depth-wise convolution needs 441 weights per channel; split into 21×1 plus 1×21, it needs only 42, more than 10 times fewer. For the 160 channels of MSCAN-T's third stage, that's 70,560 weights against 6,720.
The authors give two reasons. One is cost, as just calculated; the other is that segmentation scenes contain many long, thin things, like people and telephone poles, and long, thin kernels happen to suit such shapes.
Four Sizes
MSCAN is a four-stage pyramid at 1/4, 1/8, 1/16 and 1/32 of the input resolution, and each stage begins with a stride-2 3×3 convolution for downsampling. The authors made four sizes (Table 2 of the paper):
| Model | Channels | Blocks | Params |
|---|---|---|---|
| SegNeXt-T | 32/64/160/256 | 3/3/5/2 | 4.3M |
| SegNeXt-S | 64/128/320/512 | 2/2/4/2 | 13.9M |
| SegNeXt-B | 64/128/320/512 | 3/3/12/3 | 27.6M |
| SegNeXt-L | 64/128/320/512 | 3/5/27/3 | 48.9M |
Also, the authors use BatchNorm in every block rather than the LayerNorm Transformers usually use, because they found BatchNorm works better for segmentation.
Decoder

The authors compared three decoders. SegNeXt uses (c), concatenating only the features of stages two to four and adding a lightweight Hamburger module to capture global context. Hamburger comes from another 2021 paper; it replaces self-attention with matrix decomposition, and its compute is linear in the number of pixels.
Unlike SegFormer, SegNeXt doesn't use the first stage's features. The authors say these features are too low-level and actually hurt results with a convolutional encoder, besides being expensive to compute.
Discussion
Ablations
The ablations are mainly on ADE20K, with ImageNet classification accuracy checked alongside.
Every part of MSCA is useful (Table 6 of the paper):
| Removed | ImageNet top-1 | ADE20K mIoU |
|---|---|---|
| (full model) | 75.9 | 41.1 |
| 7×7 branch | 74.7 | 39.6 |
| 11×11 branch | 75.2 | 39.7 |
| 21×21 branch | 75.3 | 40.0 |
| 1×1 channel mixing | 74.8 | 39.1 |
| Element-wise product (attention) | 75.5 | 40.5 |
Removing any one branch costs segmentation 1 to 1.5 points; removing the 1×1 channel mixing costs the most.
Multi-scale matters especially for segmentation. When the authors swap MSCA's three branches for a single large kernel as in VAN, the two encoders have similar ImageNet accuracy but very different segmentation results; SegNeXt-T drops from 41.0 to 39.5 and SegNeXt-S from 44.3 to 43.5 (single-scale testing). Multi-scale information that classification has no use for is something segmentation needs badly.
Decoder choice (SegNeXt-T): the SegFormer-style all-MLP decoder gets 40.3, the heavy head on stage four alone 30.9, and SegNeXt's (c) 41.1, with less compute than (a). Adding stage one to (c) nearly doubles the compute and actually drops the result to 40.7.
Several global modules were compared too (SegNeXt-B): non-local attention gets 48.6 at 40.9G of compute, Hamburger 48.5 at 34.9G, CCNet 47.3 and EMANet 48.0. Hamburger strikes the best balance between accuracy and compute.
Compared with Transformers

The horizontal axis is compute and the vertical axis mIoU, so further up and to the left is better. In both plots the red SegNeXt sits furthest up and to the left, especially in the Cityscapes plot on the left. Cityscapes images are 2048×1024, which is where the quadratic complexity of self-attention hurts most.
The specific numbers (Table 9 of the paper, single-scale testing):
| Model | Params | ADE20K | Cityscapes | Cityscapes FLOPs |
|---|---|---|---|---|
| SegNeXt-S | 13.9M | 44.3 | 81.3 | 124.6G |
| SegNeXt-B | 27.6M | 48.5 | 82.6 | 275.7G |
| HRFormer-B | 56.2M | 48.7 | 81.9 | 2,223.8G |
| SegNeXt-L | 48.9M | 51.0 | 83.2 | 577.5G |
| Mask2Former (Swin-T) | 47M | 47.7 | — | — |
The authors single out SegFormer-B2 for comparison. On Cityscapes it gets 81.0 with 717.1G FLOPs and 27.6M parameters; SegNeXt-S gets 81.3 with a sixth of the compute and half the parameters. On ADE20K, SegNeXt-B is 2.0 above SegFormer-B2 (48.5 vs. 46.5) with only 56% of the compute. SegNeXt-L, with a similar parameter count, is 3.3 above the Swin-T version of Mask2Former.
Other Datasets
- Pascal VOC 2012 test set. SegNeXt-L (with COCO pretraining) gets 90.6, slightly above EfficientNet-L2 with NAS-FPN at 90.5. The latter has 485 million parameters and was also pretrained on 300 million images nobody else has access to; SegNeXt-L has fewer than 50 million parameters.
- Real-time segmentation. On the Cityscapes test set with 768×1536 input, SegNeXt-T runs at 25 images per second on a single RTX 3090 with 78.0 mIoU, above BiSeNetV2 (75.3) and SFNet (77.8).
- Remote sensing. On the aerial iSAID dataset, even the smallest SegNeXt-T gets 68.3, above UperNet with Swin-T (64.6).
- COCO-Stuff and Pascal Context. SegNeXt-L gets 46.5 and 58.7 respectively (single-scale), both better than HRFormer-B.
Conclusion
SegNeXt argues that segmentation models need a strong encoder, multi-scale interaction, spatial attention and low compute, and that convolutions can deliver all four. Its core, MSCA, sums a few strip convolutions of different lengths and multiplies the result back onto the input element-wise, which is cheap and effective. On high-resolution Cityscapes it matches SegFormer's results with a sixth of the compute.
How much of the Transformer's edge in segmentation comes from self-attention itself, and how much from better training recipes and stronger backbones? This paper makes you want to pull the two apart. SegNeXt's experiments show that when images are high-resolution and compute is tight, the quadratic complexity of self-attention is a very real burden.
For deployment on high-resolution imagery like street scenes or aerial photos, SegNeXt is a very practical choice. It's almost all convolutions, which are easy to optimize on most inference engines.