arXiv(opens in a new tab)Computer ScienceMay 2021Cited by 12 papers on PaperVantage

Manuscript Offprint

arXiv:2105.15203

SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers

Enze Xie, Wenhai Wang, Zhiding Yu, Anima Anandkumar, J. Álvarez, Ping Luo

Abstract

We present SegFormer, a simple, efficient yet powerful semantic segmentation framework which unifies Transformers with lightweight multilayer perceptron (MLP) decoders. SegFormer has two appealing features: 1) SegFormer comprises a novel hierarchically structured Transformer encoder which outputs multiscale features. It does not need positional encoding, thereby avoiding the interpolation of positional codes which leads to decreased performance when the testing resolution differs from training. 2) SegFormer avoids complex decoders. The proposed MLP decoder aggregates information from different layers, and thus combining both local attention and global attention to render powerful representations. We show that this simple and lightweight design is the key to efficient segmentation on Transformers. We scale our approach up to obtain a series of models from SegFormer-B0 to SegFormer-B5, reaching significantly better performance and efficiency than previous counterparts. For example, SegFormer-B4 achieves 50.3% mIoU on ADE20K with 64M parameters, being 5×\times smaller and 2.2% better than the previous best method. Our best model, SegFormer-B5, achieves 84.0% mIoU on Cityscapes validation set and shows excellent zero-shot robustness on Cityscapes-C. Code will be released at: github.com/NVlabs/SegFormer\tt github.com/NVlabs/SegFormer.

1 Introduction

Figure 1: Performance vs. model efficiency on ADE20K. All results are reported with single model and single-scale inference. SegFormer achieves a new state-of-the-art 51.0% mIoU while being significantly more efficient than previous methods.

Semantic segmentation is a fundamental task in computer vision and enables many downstream applications. It is related to image classification since it produces per-pixel category prediction instead of image-level prediction. This relationship is pointed out and systematically studied in a seminal work [1], where the authors used fully convolutional networks (FCNs) for semantic segmentation tasks. Since then, FCN has inspired many follow-up works and has become a predominant design choice for dense prediction.

Since there is a strong relation between classification and semantic segmentation, many state-of-the-art semantic segmentation frameworks are variants of popular architectures for image classification on ImageNet. Therefore, designing backbone architectures has remained an active area in semantic segmentation. Indeed, starting from early methods using VGGs [1, 2], to the latest methods with significantly deeper and more powerful backbones [3], the evolution of backbones has dramatically pushed the performance boundary of semantic segmentation. Besides backbone architectures, another line of work formulates semantic segmentation as a structured prediction problem, and focuses on designing modules and operators, which can effectively capture contextual information. A representative example in this area is dilated convolution [4, 5], which increases the receptive field by “inflating” the kernel with holes.

Witnessing the great success in natural language processing (NLP), there has been a recent surge of interest to introduce Transformers to vision tasks. Dosovitskiy et al. [6] proposed vision Transformer (ViT) for image classification. Following the Transformer design in NLP, the authors split an image into multiple linearly embedded patches and feed them into a standard Transformer with positional embeddings (PE), leading to an impressive performance on ImageNet. In semantic segmentation, Zheng et al. [7] proposed SETR to demonstrate the feasibility of using Transformers in this task.

SETR adopts ViT as a backbone and incorporates several CNN decoders to enlarge feature resolution. Despite the good performance, ViT has some limitations: 1) ViT outputs single-scale low-resolution features instead of multi-scale ones. 2) It has high computation cost on large images. To address these limitations, Wang et al. [8] proposed a pyramid vision Transformer (PVT), a natural extension of ViT with pyramid structures for dense prediction. PVT shows considerable improvements over the ResNet counterpart on object detection and semantic segmentation. However, together with other emerging methods such as Swin Transformer [9] and Twins [10], these methods mainly consider the design of the Transformer encoder, neglecting the contribution of the decoder for further improvements.

This paper introduces SegFormer, a cutting-edge Transformer framework for semantic segmentation that jointly considers efficiency, accuracy, and robustness. In contrast to previous methods, our framework redesigns both the encoder and the decoder. The key novelties of our approach are:

  • A novel positional-encoding-free and hierarchical Transformer encoder.
  • A lightweight All-MLP decoder design that yields a powerful representation without complex and computationally demanding modules.
  • As shown in Figure 1, SegFormer sets new a state-of-the-art in terms of efficiency, accuracy and robustness in three publicly available semantic segmentation datasets.

First, the proposed encoder avoids interpolating positional codes when performing inference on images with resolutions different from the training one. As a result, our encoder can easily adapt to arbitrary test resolutions without impacting the performance. In addition, the hierarchical part enables the encoder to generate both high-resolution fine features and low-resolution coarse features, this is in contrast to ViT that can only produce single low-resolution feature maps with fixed resolutions. Second, we propose a lightweight MLP decoder where the key idea is to take advantage of the Transformer-induced features where the attentions of lower layers tend to stay local, whereas the ones of the highest layers are highly non-local. By aggregating the information from different layers, the MLP decoder combines both local and global attention. As a result, we obtain a simple and straightforward decoder that renders powerful representations.

We demonstrate the advantages of SegFormer in terms of model size, run-time, and accuracy on three publicly available datasets: ADE20K, Cityscapes, and COCO-Stuff. On Citysapces, our lightweight model, SegFormer-B0, without accelerated implementations such as TensorRT, yields 71.9% mIoU at 48 FPS, which, compared to ICNet [11], represents a relative improvement of 60% and 4.2% in latency and performance, respectively. Our largest model, SegFormer-B5, yields 84.0% mIoU, which represents a relative 1.8% mIoU improvement while being 5 ×\times faster than SETR [7]. On ADE20K, this model sets a new state-of-the-art of 51.8% mIoU while being 4 ×\times smaller than SETR. Moreover, our approach is significantly more robust to common corruptions and perturbations than existing methods, therefore being suitable for safety-critical applications. Code will be publicly available.

References (76)

  • Fully convolutional networks for semantic segmentation
  • Semantic image segmentation with deep convolutional nets and fully connected CRFs
  • Split-attention networks
  • Deeplab: Semantic image segmentation with deep convolutional nets, atrous convolution, and fully connected CRFs
  • Multi-scale context aggregation by dilated convolutions
  • Transformers for image recognition at scale
  • CVPR, 2021
  • Pyramid vision transformer: A versatile backbone for dense prediction without convolutions
  • Swin transformer: Hierarchical vision transformer using shifted windows
  • Twins: Revisiting spatial attention design in vision transformers
  • Icnet for real-time semantic segmentation on high-resolution images
  • Deep residual learning for image recognition
  • Imagenet classification with deep convolutional neural networks
  • Very deep convolutional networks for large-scale image recognition
  • Selective kernel networks
  • Mixed link networks
  • Pyramid scene parsing network
  • Denseaspp for semantic segmentation in street scenes
  • Large kernel matters–improve semantic segmentation by global convolutional network
  • Encoder-decoder with atrous separable convolution for semantic image segmentation
  • Ocnet: Object context network for scene parsing
  • Context prior for scene segmentation
  • Object-contextual representations for semantic segmentation
  • Context encoding for semantic segmentation
  • Context-reinforced semantic segmentation
  • Refinenet: Multi-path refinement networks for high-resolution semantic segmentation
  • Contextnet: Exploring context and detail for semantic segmentation in real-time
  • Cgnet: A light-weight context guided network for semantic segmentation
  • Adaptive pyramid context network for semantic segmentation
  • Boundary-aware feature propagation for scene segmentation
  • Semantic segmentation with boundary neural fields
  • Improving semantic segmentation via decoupled body and edge supervision
  • Segfix: Model-agnostic boundary refinement for segmentation
  • Joint semantic segmentation and boundary detection using iterative pyramid contexts
  • Gated-scnn: Gated shape cnns for semantic segmentation
  • Learning a discriminative feature network for semantic segmentation
  • Semantic image segmentation with task-specific edge detection using cnns and a discriminatively trained domain transform
  • Dual attention network for scene segmentation
  • Non-local neural networks
  • Squeeze-and-attention networks for semantic segmentation
  • Ccnet: Criss-cross attention for semantic segmentation
  • Pyramid attention network for semantic segmentation
  • Psanet: Point-wise spatial attention network for scene parsing
  • Expectation-maximization attention networks for semantic segmentation
  • Gcnet: Non-local networks meet squeeze-excitation networks and beyond
  • Segmenting transparent object in the wild with transformer
  • Squeezenas: Fast neural architecture search for faster semantic segmentation
  • Fasterseg: Searching for faster real-time semantic segmentation
  • Learning dynamic routing for semantic segmentation
  • Auto-deeplab: Hierarchical neural architecture search for semantic image segmentation
  • Fast neural architecture search of compact semantic segmentation models via auxiliary cells
  • End-to-End object detection with transformers
  • Tokens-to-token vit: Training vision transformers from scratch on imagenet
  • Conditional positional encodings for vision transformers
  • Transformer in transformer
  • Crossvit: Cross-attention multi-scale vision transformer for image classification
  • Localvit: Bringing locality to vision transformers
  • Cvt: Introducing convolutions to vision transformers
  • Co-scale conv-attentional image transformers
  • Levit: a vision transformer in convnet’s clothing for faster inference
  • Transtrack: Multiple-object tracking with transformer
  • Trackformer: Multi-object tracking with transformers
  • Pre-trained image processing transformer
  • Transreid: Transformer-based object re-identification
  • Colorization transformer
  • Training vision transformers for image retrieval
  • Transformer is all you need: Multimodal multitask learning with a unified transformer
  • How much position information do convolutional neural networks encode? arXiv, 2020
  • Understanding the effective receptive field in deep convolutional neural networks
  • The cityscapes dataset for semantic urban scene understanding
  • Scene parsing through ade20k dataset
  • Coco-stuff: Thing and stuff classes in context
  • Axial-deeplab: Stand-alone axial-attention for panoptic segmentation
  • The mapillary vistas dataset for semantic understanding of street scenes
  • Benchmarking the robustness of semantic segmentation models
  • Attention is all you need