Computer Vision Lab Models Mask2Former (R50)

Mask2Former (R50)

Masked-attention mask transformer, universal segmentation

Knowledge card: a single architecture that outperforms specialised models in semantic, instance and panoptic segmentation; each query predicts a mask and a class, and masked cross-attention speeds up convergence and improves accuracy.

SegmentationKnowledge card

ArchitectureMasked-attention mask transformer, universal segmentation
TaskSegmentation
Training dataCOCO 2017 / ADE20K / Cityscapes
the number of parameters≈44M (R50, paper)
FrameworkPyTorch (Detectron2)
File size—
LicenceWeights: CC BY-NC 4.0; most of the code MIT
Where it runsKnowledge card only
Official sourcegithub.com

Published metrics (from the official source, not measured by this site)

MetricValueEvaluation dataSource
PQ51.9COCO panoptic val (R50, 50 epochs)Source
mask AP43.7COCO instance val (R50, 50 epochs)Source

Architecture diagram

Architecture diagram Mask2Former (R50)Transformer decoderInputBackbone (R50 / Swin)Pixel decodermulti-scale deformable attention ×6Per-pixel embeddings1/4 resolutionMulti-scale features1/32, 1/16, 1/8 (round robin)N learnable queriese.g. 100Masked cross-attentionattend inside predicted maskSelf-attentionFFN× 9 layersClass per queryK classes + ∅Mask embeddingper querymask = σ(embedding · pixel features)
Mask2Former by Cheng et al. (2022): one architecture for semantic, instance and panoptic segmentation. A multi-scale pixel decoder, and a transformer decoder that applies «masked cross-attention», restricting each query's attention to its predicted mask.
  • Input / output
  • Convolutional layer
  • Attention / transformer
  • Composite block
  • Embedding / tokens / queries
  • Memory / intermediate features
  • Output head
  • Operation (add, multiply, merge)

Detailed model explanation

Idea and intuition

Mask2Former offers one architecture for all kinds of segmentation: semantic, instance and panoptic. The unifying idea is «mask classification»: the model predicts a set of N binary masks, each with a class. Semantic segmentation merges masks of the same class, instance segmentation keeps them separate, and panoptic segmentation combines both cases.

Components

  • Backbone (ResNet or Swin) outputs multi-scale features.
  • Pixel decoder (pixel decoder) of the MSDeformAttn type upsamples the features and produces «pixel embeddings» at 1/4 resolution.
  • Transformer decoder with N queries, in which attention cycles through the 1/32, then 1/16, then 1/8 scales.
  • Masked attention (masked attention): each query attends only to the pixels inside the mask it predicted in the previous layer, so it focuses on its region and converges faster.

Mathematical formulation

X_l = \mathrm{softmax}\big(\mathcal M_{l-1} + Q_l K_l^{\top}\big)V_l + X_{l-1},\qquad \mathcal M_{l-1}(x,y)=\begin{cases}0 & M_{l-1}(x,y)=1\\ -\infty & \text{otherwise}\end{cases}

The mask of each query is computed as a dot product between the query embedding and the pixel embeddings: M = \sigma(\mathcal E_{q}\,\mathcal E_{pixel}^{\top}), and Hungarian matching is used as in DETR, with the mask loss computed on randomly sampled points to save memory.

Performance

According to the model page in the official repository: with an R50 backbone on COCO it reaches PQ = 51.9 for panoptic segmentation and AP = 43.7 for instance segmentation.

Strengths and limitations

  • Strength: one architecture for three tasks with strong results.
  • Strength: masked attention speeds up convergence compared with MaskFormer.
  • Limitation: computationally heavy and needs long training.
  • Limitation: the official model weights are licensed CC BY-NC 4.0 (non-commercial).

Uses

Panoptic, instance and semantic segmentation, video segmentation.

Runtime requirements

GPU.

How to load

Not loaded in the lab (knowledge card).

References

  1. B. Cheng, I. Misra, A. G. Schwing, A. Kirillov, R. Girdhar (2021).Masked-attention Mask Transformer for Universal Image Segmentation. arXiv:2112.01527 (CVPR 2022). doi:10.48550/arXiv.2112.01527
  2. N. Carion, F. Massa, G. Synnaeve, N. Usunier, A. Kirillov, S. Zagoruyko (2020).End-to-End Object Detection with Transformers. arXiv:2005.12872 (ECCV 2020). doi:10.48550/arXiv.2005.12872
  3. A. Kirillov, K. He, R. Girshick, C. Rother, P. Dollár (2019).Panoptic Segmentation. CVPR 2019. doi:10.1109/CVPR.2019.00963

Related algorithms