Per-Pixel Classification is Not All You Need for Semantic Segmentation

Bowen Cheng, Alexander G. Schwing, Alexander Kirillov

TL;DR

MaskFormer challenges the long-standing paradigm of treating semantic segmentation as a per-pixel classification problem. By shifting to a unified "mask classification" approach—predicting a set of binary masks each associated with a single global class label—it unifies semantic and panoptic segmentation under a single architecture. This simple shift not only streamlines the pipeline but also yields state-of-the-art results while significantly reducing computational overhead.

What Problem Does This Paper Address?

For years, computer vision has treated different segmentation tasks as fundamentally distinct problems requiring different architectural paradigms:

  • Semantic Segmentation (labeling every pixel with a category like "sky" or "road") has been dominated by per-pixel classification.
  • Instance Segmentation (identifying and separating distinct objects like "car 1" and "car 2") relies on mask classification, where models propose regions and classify them as a whole.

This divide creates a fragmented landscape. Furthermore, per-pixel classification approaches struggle to scale efficiently when the number of categories becomes very large, and they lack the flexibility to output a variable number of regions. The authors of this paper ask a fundamental question: Is per-pixel classification actually necessary for semantic segmentation, or can a single mask classification model unify both tasks and deliver superior performance?

Figure 1: Per-pixel classification vs. mask classification. (left) Semantic segmentation with per- pixel classification applies the same classification loss to each location. (right) Mask classification predicts a set of binary masks and assigns a single class to each mask. Each prediction is supervised with a per-pixel binary mask loss and a classification loss. Matching between the set of predictions and ground truth segments can be done either via bipartite matching similarly to DETR [4] or by fixed matching via direct indexing if the number of predictions and classes match, i.e., if N = K.

Methods

The authors introduce MaskFormer, a clean, box-free architecture that seamlessly transitions semantic segmentation into a mask classification paradigm. The model consists of three main components:

  1. Pixel-level Module: A standard convolutional or Transformer backbone extracts low-resolution image features, which a lightweight pixel decoder (based on an FPN architecture) upsamples to produce high-resolution per-pixel embeddings.
  2. Transformer Module: A standard Transformer decoder takes a set of $N$ learnable queries and attends to the image features, outputting $N$ per-segment embeddings that capture global context.
  3. Segmentation Module: A Multi-Layer Perceptron (MLP) converts the per-segment embeddings into $N$ mask embeddings. The final binary mask predictions are generated via a simple dot product between these mask embeddings and the per-pixel embeddings. Concurrently, a linear classifier predicts a class probability distribution (including a "no object" $\emptyset$ token) for each mask.

During training, predictions are matched to ground-truth segments using bipartite matching via the Hungarian algorithm, optimized by a combination of cross-entropy classification loss and a binary mask loss (focal loss + dice loss).

Figure 2: MaskFormer overview. We use a backbone to extract image features F. A pixel decoder gradually upsamples image features to extract per-pixel embeddings Epixel. A transformer decoder attends to image features and produces N per-segment embeddings Q. The embeddings independently generate N class predictions with N corresponding mask embeddings Emask. Then, the model predicts N possibly overlapping binary mask predictions via a dot product between pixel embeddings Epixel and mask embeddings Emask followed by a sigmoid activation. For semantic segmentation task we can get the final prediction by combining N binary masks with their class predictions using a simple matrix multiplication (see Section 3.4). Note, the dimensions for multiplication N are shown in gray.

Datasets

MaskFormer was rigorously evaluated across both semantic and panoptic segmentation tasks using the following datasets:

  • Semantic Segmentation: ADE20K (150 classes), COCO-Stuff-10K (171 classes), Cityscapes (19 classes), Mapillary Vistas (65 classes), and ADE20K-Full (a challenging open-vocabulary setup with 847 classes).
  • Panoptic Segmentation: COCO panoptic (133 categories) and ADE20K-Panoptic (150 categories).

Key Insights and Ideas

  • The Power of Generality: Mask classification is a naturally superior abstraction. It easily handles both "stuff" (amorphous regions like sky and grass) and "things" (distinct objects) without needing bounding boxes or task-specific modifications.
  • Vocabulary Scalability: As the number of semantic categories grows, per-pixel classification becomes memory-intensive and prone to fine-grained errors. MaskFormer decouples the number of predicted masks from the total category count, making it highly effective for large-vocabulary datasets (like ADE20K-Full).
  • Box-Free Simplification: Unlike prior models like DETR that rely on bounding box predictions to match objects, MaskFormer matches predictions directly using mask and class qualities. This makes it a simpler, more direct solution for handling amorphous background regions ("stuff") that do not fit neatly into bounding boxes.

Key Results

MaskFormer achieved state-of-the-art performance across multiple competitive benchmarks:

  • Semantic Segmentation: On the ADE20K validation set, MaskFormer paired with a Swin-L Transformer backbone achieved a state-of-the-art 55.6 mIoU, outperforming the strong per-pixel Swin-UperNet baseline by 2.1 mIoU while requiring 10% fewer parameters and 40% fewer FLOPs.
  • Large Vocabulary Advantage: On the 847-class ADE20K-Full dataset, MaskFormer outperformed its per-pixel baseline by a substantial 3.5 mIoU (17.4 vs 13.9).
  • Panoptic Segmentation: On COCO panoptic val, MaskFormer achieved 52.7 PQ, outperforming the previous state-of-the-art Max-DeepLab model and beating DETR by 2.2 PQ using identical backbones.
Table 1: Semantic segmentation on ADE20K val with 150 categories. Mask classification-based MaskFormer outperforms the best per-pixel classification approaches while using fewer parameters and less computation. We report both single-scale (s.s.) and multi-scale (m.s.) inference results with ±std. FLOPs are computed for the given crop size. Frames-per-second (fps) is measured on a V100 GPU with a batch size of 1.3 Backbones pre-trained on ImageNet-22K are marked with †.

Limitations and Future Work

While MaskFormer excels on complex datasets with large numbers of classes, its advantages are less pronounced on datasets with few categories and high spatial resolution, such as Cityscapes (19 classes). On these datasets, MaskFormer performs on par with per-pixel baselines but does not dramatically outperform them.

The authors note that while MaskFormer provides superior recognition quality ($RQ^{st}$), it slightly lags behind in fine-grained pixel-level mask quality ($SQ^{st}$) on simpler datasets. Future work will likely focus on improving the pixel-level precision of mask-based architectures to close this gap entirely.

Summary updated

BibTeX
@inproceedings{cheng2021per,
  author = {Bowen Cheng and Alexander G. Schwing and Alexander Kirillov},
  title = {{Per-Pixel Classification is Not All You Need for Semantic Segmentation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=zZh1Z9y0wpT},
}
Figure