Skip to content
module

Mask2Former

10 members
lucid.models.vision.mask2former

Mask2Former (Cheng et al., CVPR 2022).

Paper: "Masked-attention Mask Transformer for Universal Image Segmentation"

Semantic Segmentation
Paper

Cheng, Bowen, et al. "Masked-attention Mask Transformer for Universal Image Segmentation." Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2022, pp. 1290–1299.

Overview

Mask2Former generalises MaskFormer into a single architecture that wins on semantic, instance, and panoptic segmentation simultaneously. It keeps the mask-classification framing — NN object queries each predict a class and a binary mask — and improves it with three orthogonal changes.

Masked cross-attention. In every decoder layer the queries attend only to feature locations that the previous layer already considered foreground for that query:

attnij=softmaxj ⁣(QiKj⊤/d+Mij ℓ−1),\mathrm{attn}_{ij} = \mathrm{softmax}_j\!\bigl( Q_i K_j^{\top} / \sqrt{d} + \mathcal{M}_{ij}^{\,\ell-1} \bigr),

where Mijℓ−1=0\mathcal{M}^{\ell-1}_{ij} = 0 if the predicted binary mask of query ii at layer ℓ−1\ell - 1 activates pixel jj and −∞-\infty otherwise. This confines query updates to plausible mask regions and accelerates convergence.

Multi-scale features. The decoder layers cycle through three pyramid levels (P3,P4,P5)(P_3, P_4, P_5) of an enhanced FPN-style pixel decoder, so high-resolution semantic detail and broad contextual features are both available to every query.

Improved pixel decoder. A multi-scale deformable-attention encoder fuses the backbone feature maps before producing the per-pixel embeddings against which the query embeddings are dotted to form binary masks.

Training keeps MaskFormer's Hungarian-matched class CE + mask BCE/Dice objective and its auxiliary losses at intermediate decoder layers, but computes the mask term on sampled points rather than densely: Section 3.2.2 draws K=12,544K = 12{,}544 (112×112112 \times 112) points by uniform plus importance sampling, in both the matching and the final loss, cutting training memory roughly 3x. That point-sampled loss is one of the paper's three enumerated contributions, alongside masked attention and the multi-scale strategy described above. Mask2Former sets a new SOTA on each of ADE20K, Cityscapes, and COCO with a single model, eliminating the need for task-specific architectures.

Classes

Functions

Weights