PEM

PEM (Prototype-based Efficient MaskFormer) is an efficient multi-task image segmentation architecture.

  • Paper: Niccolò Cavagnero, Gabriele Rosi et al. (Politecnico di Torino / Focoos AI), PEM: Prototype-based Efficient MaskFormer for Image Segmentation, CVPR 2024, arXiv:2402.19422.
  • Architecture: keeps the Mask2Former meta-architecture (backbone → pixel decoder → query-based Transformer decoder, mask classification) but replaces its two expensive parts.
  • Prototype-based cross-attention: the masked cross-attention becomes PEM-CA, which attends to one selected pixel per query instead of all pixels.
  • Pixel decoder: the deformable-attention pixel decoder becomes a fully convolutional FPN with context-based self-modulation and deformable convolutions.
  • Headline result: with a ResNet50, 61.1 PQ on Cityscapes panoptic at 13.8 FPS (Mask2Former: 62.1 PQ at 4.1 FPS) and 45.5 mIoU on ADE20K semantic at 35.7 FPS.
  • Standing: the fastest universal (semantic + panoptic) architecture in its comparison.

Motivation

MaskFormer-family models (Mask2Former, kMaX-DeepLab) unify semantic and panoptic segmentation under one DETR-style set-prediction objective (DETR), but their cost is dominated by (i) cross-attention between queries and high-resolution pixel features, which scales with , and (ii) a pixel decoder built from multi-scale deformable attention. Efficient real-time segmenters exist, but each targets a single task (BiSeNet, STDC, DDRNet, PIDNet for semantic; UPSNet, Panoptic-DeepLab, RealTimePan for panoptic). PEM aims to be both universal and fast enough for edge deployment. The closest universal-and-fast competitor is YOSO.

Architecture

PEM architecture: backbone, efficient multi-scale pixel decoder with CSM and deformable convolutions, prototype-based Transformer decoder
Fig. 2: backbone features go through CSM modules and are fused top-down with deformable convolutions; feed the PEM-CA decoder blocks, is multiplied with the refined queries to produce masks.

  • Backbone — features at strides 4, 8, 16, 32 (). ResNet50 by default; STDC1/STDC2 for the faster variants.
  • Pixel decoder — produces ().
  • Transformer decoder — takes and learnable queries , returns refined queries . Masks are ; class probabilities come from a linear classifier on (with a “no object” class), as in Mask2Former.

Prototype-based masked cross-attention (PEM-CA)

PEM-CA: prototype selection by argmax over the masked similarity matrix, then element-wise query–prototype interaction
Fig. 3: the token dimension shrinks from to after prototype selection; everything downstream is element-wise.

The premise: as training progresses, pixels belonging to one object become close in feature space, so using all of them to refine that object’s query is redundant. One representative pixel per query — its prototype — suffices.

Features and queries are projected into a shared -dimensional space, giving and . The similarity matrix and selection are

where the mask is the Mask2Former masked-attention mask, built from the binarized mask prediction of the previous decoder layer resized to the feature resolution:

so a prototype can only be picked among current foreground pixels. Selection is multi-head: features and queries are split along channels, so each channel group of a query can pick a different pixel.

Because each query now has exactly one matched token, the query–prototype interaction needs no pairwise attention (in the spirit of SwiftFormer / MobileViT V2 additive attention):

with , , normalized across channels and scaled by a learnable ; the scaled interaction reweights the prototypes additively. Cross-attention cost no longer grows with the number of pixels — at Cityscapes resolution, PEM-CA is about faster than masked cross-attention, with the gap widening as resolution grows (Fig. 4 of the paper).

Efficient multi-scale pixel decoder

Mask2Former’s pixel decoder is an FPN plus deformable attention, which gives (i) global context, (ii) input-dependent weights and (iii) a deformable receptive field. PEM keeps all three properties with cheaper ops.

Context-based self-modulation (CSM) — squeeze-and-excitation style. Backbone features are projected to (channels ), and

where the MLP is two convolutions. This injects a global scene representation and dynamic channel weights (properties i and ii) using only convs, normalizations and element-wise products.

Feature aggregation — top-down FPN with deformable convolutions (property iii):

The lowest-resolution level additionally receives a pooled scene vector, and the highest-resolution level has no deformable conv (it is only used for the final mask product).

Training and losses

Same loss and recipe as Mask2Former: classification with binary cross-entropy, masks with BCE + Dice, Hungarian matching, deep supervision at every decoder block.

Hyperparameters

ItemValue
OptimizerAdamW, cosine LR schedule
Learning rate0.0007 (Cityscapes), 0.0004 (ADE20K); 0.1× multiplier on the backbone
Weight decay0.05
Batch size32
Iterations90k (Cityscapes), 160k (ADE20K)
Loss weights2.0 classification (BCE), 5.0 mask BCE, 5.0 Dice
BackboneResNet50, ImageNet-1k pretrained (also STDC1/STDC2)
Decoder2 transformer decoder stages (3 PEM-CA blocks each), hidden dim 256, 8 heads, FFN expansion 8
Queries100
Pixel decoder hidden dim128
Train cropCityscapes 512×1024 (full 1024×2048 at inference); ADE20K 512×512 semantic, 640×640 panoptic (short side resized to crop at inference)

Latency/FPS: PyTorch 1.12, FP32, V100, batch size 1. Task-specific baselines on ADE20K were retrained (160k iters, AdamW, LR 0.0004, wd 0.05, crop 512×512) since they were not published there.

Results

Panoptic segmentation, ResNet50 (FPS on V100):

MethodCityscapes PQFPSADE20K PQFPS
Mask2Former62.14.139.719.5
YOSO59.711.138.035.4
PEM61.113.838.535.7

On Cityscapes PEM has 237 GFLOPs / 35.6M params vs. 519G / 44.0M for Mask2Former. It is PQ over YOSO, mostly from things ( PQ; stuff is equal at 66.1). kMaX-DeepLab (42.3 PQ on ADE20K) is more accurate but slower.

Semantic segmentation:

MethodBackboneCityscapes mIoUFPSADE20K mIoUFPS
Mask2FormerR5079.46.647.221.5
YOSOR5079.411.144.735.3
PIDNet-L–80.931.140.565.4
PEMSTDC178.324.339.643.6
PEMSTDC279.022.045.036.3
PEMR5079.913.845.535.7

On Cityscapes only the hand-engineered task-specific PIDNet beats PEM-R50 in mIoU; on ADE20K PEM beats every task-specific model by a wide margin (+5 mIoU over PIDNet-L) — with the caveat that those baselines were retrained by the authors.

Ablations (Cityscapes panoptic)

Cross-attention variant (cumulative latency of the cross-attention modules):

VariantPQPQLatency
Cross-attention (MaskFormer)58.447.411.4 ms
Masked CA (Mask2Former)60.452.017.4 ms
PEM-CA, no prototypes (sum-aggregate tokens)48.724.75.6 ms
PEM-CA, no masking57.847.06.8 ms
PEM-CA61.154.39.8 ms
  • Tokens cannot be naively collapsed: replacing prototype selection by summation costs 13.4 PQ (almost 20 PQ). Masking the selection to foreground is worth 3.3 PQ. The losses concentrate on things, i.e. prototypes matter for separating instances.
  • PEM-CA beats even full masked cross-attention in PQ while being faster.

Pixel decoder (total model latency): removing CSM costs >1 PQ and ~3 PQ; replacing deformable with standard convs costs 4 PQ and ~7 PQ. PEM with the MaskFormer pixel decoder gets 57.8 PQ (84.7 ms), with Mask2Former’s decoder 61.4 PQ (131.6 ms) vs. PEM’s 61.1 PQ (72.4 ms) — equal accuracy at roughly twice the FPS.

Other: queries give 58.7/61.1/61.0 PQ (225G/237G/275G FLOPs), so 100 is the sweet spot. Performance stays robust with a single decoder stage (3 layers), giving a speed/accuracy knob; without any cross-attention layers, ADE20K PQ collapses to nearly zero, so query refinement is essential.

Limitations

  • Only semantic and panoptic segmentation are evaluated — no instance segmentation and no COCO.
  • Only Cityscapes and ADE20K, ResNet50/STDC backbones; no results with large or transformer backbones.
  • Still slower than the best hand-engineered single-task real-time models (e.g. PIDNet) on Cityscapes, and 1 PQ below Mask2Former on Cityscapes panoptic.
  • A hard argmax selects a single pixel per query per head; the ablation shows the mechanism is sensitive to the mask, so quality relies on the previous layer’s mask predictions.

See also

  • Mask2Former — the architecture PEM slims down; masked attention is the mechanism PEM-CA builds on.
  • Segmentation Head Comparison — where Mask2Former’s mask-classification head sits among other mask heads.
  • DETR — the set-prediction / learnable-query formulation underlying all MaskFormer-family models.
  • YOLACT — another prototype-based segmentation design, though its prototypes are mask bases rather than selected feature tokens.
  • PANet — the class-prototype idea in few-shot segmentation, a different use of the word “prototype”.
  • Attention Is All You Need — the attention operation PEM-CA replaces with element-wise interactions.