Skip to content
module

MaskFormer

7 members
lucid.models.vision.maskformer

MaskFormer (Cheng et al., NeurIPS 2021).

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

Semantic Segmentation
Paper

Cheng, Bowen, et al. "Per-Pixel Classification is Not All You Need for Semantic Segmentation." Advances in Neural Information Processing Systems, 2021.

Overview

MaskFormer recasts semantic segmentation as a mask-classification problem rather than the standard per-pixel-classification one. Instead of predicting a KK-way softmax at every pixel, the model emits NN queries; each query produces a class label and a binary mask, and the final segmentation is the soft sum

segk[h,w]=∑n=1Nsoftmax(c^n)k σ(m^n[h,w]),\mathrm{seg}_{k}[h, w] = \sum_{n=1}^{N} \mathrm{softmax}(\hat{c}_n)_k \, \sigma(\hat{m}_n[h, w]),

where c^n∈RK+1\hat{c}_n \in \mathbb{R}^{K+1} is the per-query class logit and m^n\hat{m}_n is its binary mask logit. The argmax over kk yields the predicted label map.

The architecture has three modules:

  • Pixel decoder — an FPN-like up-sampler that produces a per-pixel embedding Epixel∈RCϵ×H/4×W/4\mathcal{E}_{\mathrm{pixel}} \in \mathbb{R}^{C_\epsilon \times H/4 \times W/4}.
  • Transformer decoder — NN learnable queries attend to a flattened backbone feature, producing per-query embeddings Equery∈RN×Cϵ\mathcal{E}_{\mathrm{query}} \in \mathbb{R}^{N \times C_\epsilon}.
  • Heads — a linear classifier on each query and a dot-product Equery⋅Epixel\mathcal{E}_{\mathrm{query}} \cdot \mathcal{E}_{\mathrm{pixel}} to produce per-query masks.

Training uses Hungarian matching (as in DETR) between predicted and ground-truth segments and combines cross-entropy on the class logits with focal/BCE + Dice losses on the mask logits.

The key insight — that mask classification subsumes per-pixel classification — also unifies semantic and instance segmentation under one model, foreshadowing the more general Mask2Former.

Classes

Functions

Weights