RefT

RefT (Reference Twice) is a unified baseline for Few-Shot Instance Segmentation (FSIS) that abandons the Region Proposal Network entirely and builds on a mask-transformer detector (Mask2Former) instead.

  • Paper: Yue Han, Jiangning Zhang, Yabiao Wang, Chengjie Wang, Yong Liu, Lu Qi, Xiangtai Li, Ming-Hsuan Yang (Zhejiang University APRIL Lab / Youtu Lab Tencent / TikTok Singapore / UC Merced), Reference Twice: A Simple and Unified Baseline for Few-Shot Instance Segmentation, arXiv:2301.01156. The PDF in this vault is v3, 8 August 2024, typeset in the IEEE journal style; it names no venue on the paper itself, so it is cited here as an arXiv preprint.
  • Core idea: the support branch should be consulted twice.
  • First reference (feature level): masked-pooled class prototypes reweight the query feature map.
  • Second reference (query level): the support branch’s own object queries are cross-attended into the query image’s object queries.
  • Real contribution: the second reference. The paper shows empirically that after base training alone, support object queries already encode both the localization and the categorization of novel-class instances, so a plain multi-head cross-attention is enough to transfer that knowledge, with no elaborate spatial-correlation module required.

RPN-based dual-branch framework versus the Reference Twice framework, and COCO 10-shot performance

Problem setup: FSIS, gFSIS, iFSIS

The object classes are split into a disjoint base set and novel set , with and . A model is trained on abundant samples of , then fine-tuned with samples per class of , and finally must detect and segment every instance of in a query image. The three settings differ only in which classes appear in fine-tuning and in testing:

SettingThe difficulty
FSIS (standard)pure novel-class generalization
gFSIS (generalized)novel classes without losing base classes
iFSIS (incremental) onlyas above, but base data is inaccessible — catastrophic forgetting

iFSIS is the hardest and the practically motivated one: base training data may be unavailable at adaptation time for data-security or storage reasons. Metrics are COCO-style AP at IoU reported separately for novel and base classes, nAP and bAP.

This is a strictly harder problem than the few-shot semantic segmentation of HSNet. There, each episode is a class-agnostic binary foreground/background problem: one class, one mask, no instances, and the model never has to say which class it found. FSIS requires (i) separating instances, (ii) emitting an actual class label from a fixed vocabulary, and (iii) in the gFSIS/iFSIS variants, keeping the 60 base classes working at the same time. HSNet’s prototype-free dense-correspondence trick has nothing to say about the classification half of that problem, which is exactly where RefT’s ablations show the errors concentrate.

Motivation: two failure modes of RPN-based FSIS

1. RPN overfitting suppresses novel objects. Existing FSIS methods (Meta R-CNN, FGN, MTFA, iFS-RCNN) are Mask R-CNN derivatives. The RPN is trained on base classes with enough data to learn a base-class objectness rather than generic objectness, and consequently scores novel-class regions as background. Supervision collapses before the detection head is ever reached. Mitigations in the literature — mining additional samples, unfreezing more parameters — add data or parameters rather than removing the cause.

2. Dual-branch prototypes need complex spatial correlation. The second family aggregates support features into class prototypes and injects them into the query branch (channel-wise multiplication in Meta R-CNN, three-stage aggregation in FGN). Pooling into a prototype destroys spatial structure, so later work replaced it with dense query–support spatial-correlation attention — expensive, and requiring careful design to avoid under-exploiting the support cues.

RefT’s answer to (1) is to swap the meta-architecture: a query-based mask transformer has no proposal stage to overfit. Its answer to (2) is to observe that the object queries produced by the support branch of that same transformer are a far better carrier of class information than any pooled prototype, because they already entangle “where the instance is” with “what class it is”.

The two empirical findings

Both come from probing a Mask2Former after base training only, before any novel fine-tuning:

  • Support query localization (Tab. 2). Feeding novel-class support images through the model and comparing predicted masks to ground truth: with the top- object queries per image, gives bIoU / nIoU on base/novel classes — identical before and after novel fine-tuning. At it is (base training) versus (fine-tuned), at , versus . So the model can already localize and segment novel objects; only the class label is missing.
  • Support query categorization (Fig. 3). Cosine-similarity maps among support object queries of the 20 COCO novel classes are already block-diagonal before fine-tuning, and become sharply more so after. Object queries of the same class cluster; a t-SNE of the same queries (Fig. 8) shows the same effect.

The complementary negative result is the baseline’s error profile: a fine-tuned Mask2Former systematically misclassifies semantically similar classes (train predicted as refrigerator, Fig. 2) while its masks are fine. FSIS on a mask transformer is a classification problem, not a localization problem — which is why guidance should be injected at the query level where categorization lives.

Architecture

RefT architecture

The backbone is ResNet-50 (Swin-T/S/B in the scale-up experiments) and the meta-architecture is Mask2Former: a pixel decoder built from multi-scale deformable-attention encoder layers (the Deformable DETR MSDeformAttn operator; the figure shows five stacked stages feeding an FPN) followed by a Transformer decoder that turns learnable object queries into per-instance class logits and mask embeddings, with masked attention restricting each query’s cross-attention to its own predicted mask region. The decoder is the same set-prediction machinery as DETR and its descendants (DINO, DAB-DETR): Hungarian matching, no NMS, no anchors — hence no RPN to overfit.

Two branches share every weight:

  • Query branch: the query image at → backbone → CAL → pixel decoder → Transformer decoder → object queries .
  • Support branch: a support set of examples (an -way -shot episode) at the cheaper → the same path, but every support image is masked with its ground-truth instance mask so background and other instances are dropped, giving multi-scale support features and object queries that correspond exactly to support-class instances.

CAL — the Class Adaptation Layer is the paper’s name for the input projection layer sitting between the backbone and the pixel decoder (a single convolution mapping the channel dimension). The paper argues, and Tab. 17 confirms, that this layer is class-specific: it is the crucial thing to fine-tune when adapting a DETR-like model to new classes, and the crucial thing to protect when adapting incrementally.

Crucially, support class prototypes and support object queries are computed once for all classes and reused for every query image — a single forward pass covers all classes, unlike prior dual-branch methods that need one forward pass per class. Comparing all classes simultaneously is also what mitigates the confusion between semantically similar classes.

Reference Twice

The first and second reference modules

First reference — feature-level enhancement

Multi-scale features from the query image and from the supports (; ; feature levels) are first mapped into a common space by the weight-shared multi-scale deformable attention of the pixel decoder, giving and . Support instances are separated from background and from other instances by mask pooling with the ground-truth masks at each scale, then averaged over shots and scales into one adaptive class prototype per class:

With the prototype matrix , a multi-head attention generates a channel reweighting matrix

(linear projections omitted for clarity; is the sigmoid) and the query features are rescaled along the channel dimension:

The query feature map is thus coarsely filtered by support categories: channels that matter for the classes present in the episode are amplified. Because prototypes for all support classes enter one softmax, the operation is “one-forward-all-class” rather than the “one-forward-one-class” of previous dual-branch methods. Adaptivity comes from the episode composition: the classes present in the support set adapt to the classes appearing in the query image, and negative classes (classes absent from the query image) are explicitly sampled into the support set so training mimics inference, where prototypes for all classes — positive and negative — are available. The prototypes themselves are supervised with a cosine-similarity cross-entropy loss encouraging each to fall into its own category.

Second reference — query-level enhancement

Feature-level aggregation cannot exploit instance-wise information, because a pooled prototype is a class-discriminative vector, whereas object queries carry entangled classification and positional information. The second reference operates directly on queries.

Support object queries first pass a filter: their predicted masks are compared to the ground-truth support masks by IoU, and only the top of the queries per support image are kept. This is both a computation saver and a quality filter — it is exactly the top- regime validated by the support query localization probe above. Then a multi-head cross-attention matches query object queries against the retained support object queries:

A multi-head self-attention and one feed-forward layer follow, adapting the result to the class and mask prediction heads. That is the whole mechanism: no adaptive convolution, no auxiliary contrastive objective, no spatial correlation volume. Tab. 6 tests both alternatives — replacing the cross-attention with adaptive convolution ( nAP) or adding an auxiliary classification loss over concatenated query/support queries ( nAP, bAP) — and neither helps.

Class-Enhanced Base Knowledge Distillation for iFSIS

The problem this solves is specific to DETR-like models. In iFSIS only novel-class data is available. Freezing everything but the classification head — the RPN-era recipe of iMTFA and iFS-RCNN — does not work here, because CAL is class-specific: with CAL frozen the model barely learns novel classes at all ( nAP versus with CAL fine-tuned, Tab. 12). But fine-tuning CAL on novel-only data causes catastrophic forgetting of the base classes. Incremental-DETR attacks this with feature distillation plus logits distillation plus selective search for pseudo-labels; RefT argues CAL is the only place the distillation is needed, and drops the rest.

During iFSIS fine-tuning, only CAL, the object queries and the class head are unfrozen. An input image may contain novel-class foreground, base-class foreground and background, but only the novel annotations exist. So the ground-truth novel masks are used to mask novel objects out, and distillation is applied only to the remainder (base foreground + background):

where is the ground-truth mask of the -th novel instance and are the CAL output features of the model frozen after base training and of the model being fine-tuned.

Base-class object locations are unknown, but base-trained features already indicate them approximately, so the relative prominence of the frozen feature map serves as a spatial and channel reweighting map — the absolute mean value of each channel or pixel, normalized by a softmax:

The re-weighted base-class feature distillation loss is then

and a coefficient distillation loss keeps the reweighting maps themselves from drifting:

The final Class-Enhanced Base Class Distillation (CE-BCD) loss is

with balancing the two terms. The paper does not report a numerical value for .

Training pipeline

Two stages, both episodic (following Meta R-CNN’s protocol):

  1. Base training. Train the whole model on with abundant data, standard Mask2Former classification and mask losses, plus the cosine-similarity cross-entropy on the adaptive class prototypes. 50 epochs.
  2. Novel fine-tuning. Freeze most parameters and fine-tune only the class-specific ones: CAL, the object queries, and the class head. Nothing else is modified. For iFSIS, the class head is additionally replaced by a cosine-similarity classifier (as in iMTFA) and the CE-BCD loss is applied to CAL.

An episode samples a query image whose objects belong to classes in , plus randomly added classes absent from the query image, giving an -way -shot episode with varying between and . To reduce cost only positive-class support features and queries are actually computed; negatives are reused from previous iterations.

-shot aggregation. Shots are merged at two different points, which is worth noting: at the feature level they are averaged into a single prototype per class (the above), while at the query level they are not averaged — all sets of top- support object queries are concatenated and cross-attended jointly. Contrast HSNet, which aggregates shots only at the prediction level by voting over forward passes.

At inference, class prototypes and support object queries are computed once and for all and cached; each query image is a single forward pass covering every class.

Hyperparameters

Reported configuration (Sec. 4, “Implementation Details and Strong Baselines” and “Training and Inference Details”):

SettingValue
Main moduleMask2Former
BackboneResNet-50 (ImageNet-pretrained); ResNet-101 and Swin-T/S/B in scale-up experiments
DatasetMS-COCO 2014, 60 base / 20 novel classes (the novel 20 intersect PASCAL VOC); LVIS for generalization; FSS-1000 for cross-domain
Shots on COCO; on LVIS; on FSS-1000
Base training epochs50
Batch size8
Hardware4 × RTX 3090
OptimizerAdamW
LR schedulestep schedule; initial learning rate , “weight decay at the last epoch by 0.05”
Novel fine-tuningsame settings as base training
Unfrozen in fine-tuningCAL, object queries, class head (all else frozen)
Query image resolution
Support image resolution
Support features for 1st referenceflattened multi-scale features from the first Transformer encoder layer (Enc1)
Pooling in 1st referencemask pooling with ground-truth masks
Top- queries in 2nd reference, selected by mask IoU against ground truth
iFSIS class headcosine-similarity classifier
Episode composition-way -shot, , negatives sampled from classes absent in the query image
Evaluation protocol10 runs with examples from 10 seeds per class, averaged
Model size / cost46.4M parameters, 239.4 GFLOPs at (Mask2Former baseline: 43.7M, 226.2 GFLOPs)

The paper does not report: the number of object queries (Mask2Former’s default is 100), the number of fine-tuning iterations or epochs, data augmentation beyond “the same settings” as Mask2Former, the CE-BCD balancing weight , or individual loss weights.

Results

All COCO numbers with ResNet-50 unless noted; nAP = novel-class AP, bAP = base-class AP, at IoU .

FSIS (standard)

Instance segmentation nAP on COCO:

Method1351030
MRCN-ft-full0.6–1.21.9–
Meta R-CNN––2.84.4–
MTFA––6.68.4–
iFS-RCNN5.57.89.410.213.1
Meta-DETR––8.110.1–
Mask2Former-ft-full2.58.412.716.720.8
Mask2Former w/ CAM3.911.113.417.521.6
RefT5.112.214.218.422.5

The abstract’s headline +8.2 / +9.4 is RefT versus the best RPN-based prior (iFS-RCNN) at 10-shot ( vs ) and 30-shot ( vs ) instance segmentation. Note that most of that gap is the stronger meta-architecture — Mask2Former-ft-full alone already reaches ; RefT’s own contribution over that baseline is . The detection side (FSOD nAP) reads , substantially better than Meta-DETR at 10/30 shots () and comparable at 1/3/5.

gFSIS (generalized)

Instance segmentation, R-50:

MethodnAP 1351030bAP 1351030
MTFA2.3–6.48.4–29.9–31.331.8–
Mask2Former-ft-full2.97.68.514.717.936.135.633.436.035.2
Mask2Former w/ CAM5.29.311.216.120.333.433.232.933.533.5
RefT5.210.212.417.421.736.336.534.436.035.5

RefT gains on novel classes without trading away base classes — bAP is level with or above the plain fine-tuned baseline, whereas the CAM variant loses ~3 bAP. Detection (gFSOD) with R-50 gives nAP and bAP ; with R-101, nAP , bAP .

iFSIS (incremental)

Instance segmentation, cosine classifier:

MethodnAP 1351030bAP 1351030
iMTFA2.8–5.25.9–25.9–22.621.9–
iFS-RCNN4.0–8.810.1–––36.336.3–
Mask2Former w/ Cos3.16.39.012.418.529.028.428.428.728.6
RefT w/ Cos3.16.08.811.117.737.036.335.335.232.1

This is the clearest illustration of what CE-BCD buys: RefT trades ~1 nAP for +6 to +8 bAP over the Mask2Former baseline, i.e. it stops forgetting. On the detection side (iFSOD) RefT reaches bAP against Incremental-DETR’s at 10-shot.

LVIS and cross-domain

LVIS (; frequent + common classes as base, rare as novel; fAP/cAP/rAP): RefT reaches rAP on FSIS (+1.5 over Mask2Former-ft-full) and on gFSIS (+0.9). On iFSIS it retains base knowledge dramatically better: cAP vs (+7.0) and fAP vs (+5.9), at comparable novel performance.

COCO → FSS-1000 cross-domain (train on the 60 COCO base classes, fine-tune and test on 100 FSS-1000 classes with instance labels, disjoint from COCO base): RefT at , versus Mask2Former-ft-full , iFS-RCNN and MRCN-ft-full .

Scale-up (gFSIS, instance segmentation nAP at ): Swin-T , Swin-S , Swin-B ; bAP up to — the approach keeps improving with backbone capacity rather than overfitting.

Ablations

All on COCO minival, , R-50, gFSIS instance segmentation unless noted.

Reference twice, component by component (Tab. 9):

Baseline+1st reference+2nd referencenAPbAP
Mask2Former-ft14.736.0
Mask2Former-ft✓15.636.3
Mask2Former-ft✓16.335.5
Mask2Former-ft✓✓17.436.0

The two are complementary but asymmetric: the first (feature-level) reference contributes nAP and bAP — it is backbone feature aggregation, and since both branches share the backbone, base-class features in the support branch remain prominent, so nothing is lost. The second (query-level) reference contributes nAP but bAP: it pushes the model to rely on support object queries for classification, reducing its bias toward base classes.

Feature-level vs. query-level referencing of the same information (Tab. 11). Implementing the second reference in an image-based way — using the first reference’s adaptive class prototypes as guidance with cross-attention — gives nAP / bAP, versus for the query-level version. nAP purely from operating on object queries rather than prototypes; this is the direct evidence for the paper’s central claim.

First reference vs. Meta-DETR’s CAM (Tab. 16). Swapping in Meta-DETR’s Correlational Aggregation Module costs bAP with RefT’s support set and loss (), and bAP when additionally aligned to Meta-DETR’s one-class-per-pass support organization and sigmoid binary matching loss (). CAM handles class matching itself and leaves the class head class-agnostic, so base-class feature representations are never stored in the head.

Other design choices:

  • Support features for the first reference (Tab. 10): Res3 , Res4 , Res5 , Enc1 (flattened multi-scale features from the first encoder layer) . Larger-scale features detect small objects better; multi-scale adds another .
  • Pooling (Tab. 13): GAP , RoIAlign , MaskPool — accuracy of the extracted region tracks performance directly.
  • Query selection in the second reference (Tab. 14): sorting by mask IoU () beats sorting by score () slightly, since at small object queries exhibit high accuracy either way.
  • Number of selected queries (Tab. 15): , , , . Stable for , degrading beyond — matching the mask-quality probe of Tab. 2.
  • Which layers to fine-tune (Tab. 17): pixel decoder + queries/head nAP; + Transformer decoder ; + Res5 ; CAL + queries/head . Fine-tuning more parameters on samples overfits badly (bAP ); CAL alone generalizes best on both novel () and base ().
  • CE-BCD ablation, iFSIS (Tab. 18): plain RefT nAP / bAP; L2 weight regularization on CAL ; Incremental-DETR’s BKD loss (+3.8 bAP, nAP); Class-Enhanced BKD (+6.5 bAP, nAP).
  • iFSIS class head (Tab. 19): a Bayesian logit classifier (iFS-RCNN’s) gives over the cosine classifier’s — better, but the gain is smaller than in region-based methods, which the authors read as headroom for DETR-like models in iFSIS.
  • Transplanting RPN-era tricks into Mask2Former (Tab. 20): DCNet’s DRD module, FCT, a cosine head and iFS-RCNN’s Bayesian head all give improvements slightly smaller than or comparable to RefT’s query-level aggregation, and are orthogonal to it.

Without re-training (Tab. 21). Adding a learnable support class embedding to the support-branch query features makes the class head predict “does this object belong to the given support class?” instead of a fixed category, which turns RefT into a re-training-free detector functionally close to FS-DETR. Detection nAP at with bAP held near ; class-agnostic training helps a lot in low-shot but gains flatten as shots increase.

Cost (Tab. 23, one RTX 3090, batch size 1, ): RefT trains at s/iteration with MB VRAM and infers at s with MB, versus Mask2Former-ft / s and Meta Faster R-CNN / s. The extra training cost is one forward pass over the sampled support set; at inference the support set is preprocessed and cached, so RefT is essentially as fast as its baseline, and the small support resolution () keeps memory modest. nAP costs GFLOPs and parameters.

Limitations

  • One-shot is where it fails. The paper’s own stated limitation: a single shot makes the reference-twice guidance unreliable because the support features deviate from the true class distribution. At RefT is beaten by iFS-RCNN on FSIS ( vs nAP) and by iFS-RCNN/iMTFA on iFSIS — the gains only materialize from 3 shots up.
  • Misclassification remains the dominant error. Even with both references, the qualitative results (Figs. 10–12) show masks are usually right while class labels are often wrong; the second reference reduces but does not eliminate confusion among semantically similar classes.
  • Novel/base trade-off is not eliminated, only softened. In iFSIS, CE-BCD recovers base classes at a consistent nAP cost, and the query-level reference itself costs bAP.
  • Much of the headline gain is the meta-architecture. Against the fair Mask2Former-ft-full baseline the modules are worth nAP, not ; the paper is honest about this and frames itself as a baseline, not a peak.
  • Support masks are required at both levels. Mask pooling in the first reference and the IoU-based top- filter in the second both consume ground-truth support masks, so RefT cannot be prompted with boxes or points the way SAM or SAM3 can.
  • The class head is class-specific. Out of the box RefT cannot handle the “without re-training” / open-vocabulary setting; it needs the support-class-embedding modification, whose accuracy then saturates with more shots.
  • iFSIS numbers still trail region-based methods on novel classes at low shot, and the Bayesian-head ablation suggests the DETR-like classification head is the remaining bottleneck.

See also

  • HSNet — the few-shot semantic segmentation counterpart: class-agnostic binary masks from dense 4D correlation instead of instance masks plus class labels, and -shot aggregation by voting rather than by prototype/query fusion.
  • Deformable DETR — the MSDeformAttn operator that RefT’s shared pixel decoder (and Mask2Former’s) is built from, and the source of its multi-scale encoder.
  • DETR — the set-prediction formulation, object queries and Hungarian matching that make an RPN-free FSIS baseline possible in the first place.
  • DINO and DAB-DETR — the same object-query line, showing how much structure a query can be made to carry; RefT’s finding that support queries already encode class and location is the few-shot analogue.
  • PerSAM — the extreme opposite trade-off for “segment this concept from one example”: training-free personalization of a frozen model from a single image and mask, with no base/novel split and no fine-tuning at all.
  • SAM and SAM3 — foundation-model answers to the same problem; SAM 3 in particular accepts exemplar boxes as a concept prompt, which is the few-shot setting recast as promptable segmentation over a huge pre-trained vocabulary.
  • Your ViT is Secretly an Image Segmentation Model — argues the pixel decoder and Transformer decoder RefT inherits are largely removable given a strong enough ViT.
  • Implementing Research Papers — the unreported , query count and fine-tuning schedule here are exactly the gaps that decide whether a reproduction lands.