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.
| Architecture | Masked-attention mask transformer, universal segmentation |
|---|---|
| Task | Segmentation |
| Training data | COCO 2017 / ADE20K / Cityscapes |
| the number of parameters | ≈44M (R50, paper) |
| Framework | PyTorch (Detectron2) |
| File size | — |
| Licence | Weights: CC BY-NC 4.0; most of the code MIT |
| Where it runs | Knowledge card only |
| Official source | github.com |
Published metrics (from the official source, not measured by this site)
| Metric | Value | Evaluation data | Source |
|---|---|---|---|
| PQ | 51.9 | COCO panoptic val (R50, 50 epochs) | Source |
| mask AP | 43.7 | COCO instance val (R50, 50 epochs) | Source |
Architecture diagram
- 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
Nqueries, 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
- 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
- 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
- A. Kirillov, K. He, R. Girshick, C. Rother, P. Dollár (2019).Panoptic Segmentation. CVPR 2019. doi:10.1109/CVPR.2019.00963
