ReSA: Preserving Reference-Specified Foreground in In-Context Segmentation
Authors: Dezhao Su, Bingxu Hou, Jingdi Lei, Lin Qian, Likai Wang, Yunyun Wan
Organizations: Fudan University · Zhejiang University · Nanyang Technological University · University of Manchester · Tsinghua University · Beijing University of Posts and Telecommunications
In-context segmentation uses annotated references to specify the target and its extent in a query image. Accurately transferring this reference-specified foreground requires recovering target regions while suppressing irrelevant predictions. We propose ReSA, a reference-guided framework that unifies query adaptation and mask selection through a shared reference kernel. ReSA leverages foreground and background reference prototypes to constrain prediction changes during adaptation and guide foreground selection through reference-weighted reconstruction. This shared guidance promotes consistent use of reference information across prediction refinement and mask formation. ReSA further selects among adapted predictions and aligns boundary refinement with the selected foreground threshold. We establish a theoretical bound connecting reference-response changes during adaptation and soft reconstruction. With a frozen visual encoder and lightweight test-time adaptation, ReSA requires no offline task training. Ablation studies demonstrate improved foreground retention and effective suppression of false-positive regions, while qualitative results show more complete masks with fewer isolated artifacts. Across ten object, part, and cross-domain segmentation benchmarks, ReSA achieves the highest average mIoU among the evaluated methods, reaching 62.6% in 1-shot and 71.8% in 5-shot.
Figures & tables
Figure 2: From reference fitting to query adaptation. Columns show the query with its ground-truth target, DINOv3 feature clusters, initial probabilities p0 , probabilities after RCA, and the final mask. Probability maps share a [0,1] scale. Cyan/magenta denote ground truth/predictions. Loss ablations are in Fig. 6 (a).
Figure 3: Reference guidance from predictions to masks. A recorded 1-shot example; query ground truth is shown for visualization. Frozen DINOv3 features form the reference kernel K . Reference fitting produces p0 ; RCA adapts two copies of the head with entropy weights λ∈{1,3} while penalizing changes from Kp0 to Kpλ . RMS uses the reference weight map W (entries wi ) to fit thresholds and select (p∗,T∗) by relative reconstruction gain. TAR shifts the CRF unary scores to use T∗ and refines the coarse mask using query RGB and spatial cues. The inset shows the matched λ=1 control without the response constraint. Probability maps, thresholds, gains, and masks are recorded outputs.
Figure 4: Five-shot qualitative comparisons across ten benchmarks. FSSAM (ICML’25), INSID3 (CVPR’26), RSRM (ECCV’26), and ReSA use the same five annotated references per query (one shown). Cyan: reference masks and ground truth; magenta: predictions.
RCA
RMS
TAR
1-shot
Δ
5-shot
Δ
Base
57.3
–
67.9
–
✓
–
–
60.0
+2.7
70.3
+2.4
✓
✓
–
61.9
+4.6
70.7
+2.8
✓
–
✓
60.6
+3.3
71.3
+3.4
✓
✓
✓
62.6
+5.3
71.8
+3.9
Table 3: Module combinations. Ten-dataset mean mIoU (%). Base is p0 ; Δ subtracts its displayed score. Bold marks the best per shot.
Loss combination
1-shot
Δ
5-shot
Δ
R
56.8
−3.2
68.3
−2.0
R+C
55.2
−4.8
67.5
−2.8
R+H
53.9
−6.1
69.7
−0.6
R+C+H
60.0
–
70.3
–
Table 4: RCA loss combinations. Reference supervision is retained; ten-dataset mean mIoU (%). Δ subtracts the displayed full-objective score; bold marks the best per shot.
Figure 5: Threshold fitting. Ten-dataset mean mIoU (%) with RMS-selected probabilities fixed, without TAR.
Selection rule
1-shot
5-shot
Single branch: λ=1
61.5
70.2
Single branch: λ=3
61.0
70.6
Min D : λ∈{1,3}
61.0
70.5
Random λ∈{1,3}
61.2
70.4
RMS: λ∈{1,3}
61.9
70.7
RMS: λ∈{1,2,3}
61.8
70.7
Table 5: Branch-selection controls. Ten-dataset mean mIoU (%), without TAR, using fixed candidate probabilities and fitted thresholds. Min D selects the branch with the lowest weighted reconstruction error; random selection averages 20 seeds. Bold marks the best per shot, including ties.
Figure 6: Changes in predictions, masks, and boundaries. (a) RCA probabilities with reference supervision retained: removing the response constraint, removing entropy, and using both. (b) Masks after reference fitting (Base), then cumulative RCA, RMS, and TAR. (c) The coarse mask, CRF without threshold alignment, and TAR. Each row uses a common display region. Numbers are full-query IoUs (%); cyan/magenta denote annotations/predictions.
Figure 7: Boundary recovery and threshold alignment. Boundary IoU [ 7 ] changes across four d=∣T−0.5∣ groups: TAR–unaligned isolates alignment; TAR–coarse measures total refinement. The lower strip shows the distribution of 133,690 valid-threshold episodes. Shots are pooled within each dataset before averaging datasets.
Configuration
1-shot
5-shot
No TAR (RCA+RMS)
61.9
(−0.7)
70.7
(−1.1)
Unaligned evidence
62.2
(−0.4)
71.8
(+0.0)
No continuous evidence
62.4
(−0.2)
71.5
(−0.3)
Full TAR
62.6
71.8
Table 6: Matched refinement controls. Ten-dataset mean mIoU (%) with probabilities and coarse masks fixed. Refiners share the band, RGB/spatial terms, η=8 , and five iterations. Parentheses subtract Full TAR; bold marks the best, including ties.
Backbone
Base
Full method
Gain
DINOv2-L/14
50.5/60.8
57.0/67.5
+6.5/+6.7
DINOv3-S/16
50.5/61.0
55.4/64.2
+4.9/+3.2
DINOv3-B/16
53.8/64.8
59.6/68.9
+5.8/+4.1
DINOv3-L/16
57.3/67.9
62.6/71.8
+5.3/+3.9
Table 7: Matched backbone controls. Ten-dataset mean mIoU (%), 1-shot/5-shot. Base is first-stage p0 ; Full uses the same encoder and episodes. Gains subtract displayed Base scores.
Appendix figures & tables29 assets
Supplementary material from the paper’s appendix.
Appendix
Dataset
Folds/pools
Episodes
LVIS- 92i
10
23,000
COCO- 20i
4
4,000
PASCAL-Part
4
8,459
PACO-Part
4
10,000
ISIC
1
600
SUIM
1
3,859
Appendix
Table S1 : Evaluation episodes per shot. Counts are identical in the 1-shot and 5-shot settings. FSS uses a single test-class pool.
Parameter
Value
Frozen encoder
DINOv3 ViT-L/16
Input resolution
1024×1024
Positional basis rank
500
Optimizer
AdamW [ 30 ]
Learning rate
0.004
AdamW (β1,β2)
(0.9,0.999)
Appendix
Table S2 : Main inference parameters. Shared across all ten datasets and both shot settings.
Table S5 : Group-wise comparison. Equal-weight mean foreground IoU (%) for objects (4 datasets), parts (2), and cross-domain benchmarks (4). –: incomplete groups. Gray: averages with task-training overlap, excluded from ranking. Conventions follow Table S3 .
Figure S1 : 1-shot foreground error rates beyond LVIS- 92i . Miss is FN/(TP+FN) ; Extra is FP/(TP+FP) . Counts are pooled within each class; classes and folds are averaged equally. Bars report percentages (lower is better), with ReSA in pink; dashed lines mark ReSA’s values. Bold values indicate the lowest error. GF-SAM uses our local DINOv2-L/14 + SAM-H reproduction.
Dataset
1-shot
5-shot
Base
RCA
RCA+RMS
RCA+TAR
Full
Base
RCA
RCA+RMS
RCA+TAR
Full
LVIS- 92i
37.5
44.1
43.2
45.2
44.9
47.0
52.4
50.6
54.8
53.0
COCO- 20i
50.2
55.3
58.0
55.8
58.8
63.3
66.8
67.2
67.9
68.4
FSS-1000
81.3
84.6
84.6
86.4
86.4
86.2
87.9
87.6
89.7
89.5
PASCAL- 5i
66.6
69.8
73.4
69.9
73.8
85.2
87.6
88.2
88.1
88.9
PASCAL-Part
51.3
53.4
55.5
53.7
56.0
63.0
65.4
65.7
66.0
66.3
Appendix
Table S6 : Module combinations. Foreground mIoU (%) on 133,962 matched episodes. Base denotes the first-stage initialization p0 . Bold marks the highest displayed scores per dataset and shot, including ties.
Prediction
Branch setting
TAR
1-shot
5-shot
p0
Single prediction
–
57.7
67.1
R -only
Single prediction
–
57.8
68.1
RCA
Fixed λ=1
–
61.5
70.2
RCA
RMS: λ∈{1,3}
–
61.9
70.7
p0
Single prediction
✓
58.8
68.4
R -only
Single prediction
✓
58.8
69.4
Appendix
Table S7 : Query adaptation under matched threshold fitting and refinement. Ten-dataset mean mIoU (%) on 133,962 matched episodes. All rows use the same reference-weighted KL threshold fit. For RCA, λ weights query entropy; RMS selects between the two branches. Bold marks the best per shot.
Objective
1-shot
5-shot
R
56.8
68.3
C
57.3
67.9
H
48.9
64.0
R+C
55.2
67.5
R+H
53.9
69.7
C+H
60.0
70.4
Appendix
Table S8 : Single, pairwise, and full RCA objectives. Ten-dataset mean mIoU (%) on 133,962 matched episodes. R , C , and H denote reference supervision, conditional KL, and query entropy. The upper block uses λ=1 and T=0.5 . The lower block includes RMS and TAR and reports two decimals. Bold marks the best per shot within each block, including ties.
Initial p0
R
R+H
R+C+H
[0,0.3]
0.1/0.3
3.2/3.2
1.6/1.2
(0.3,0.5]
10.1/13.5
17.2/23.0
20.1/20.7
(0.5,0.7]
74.4/76.0
44.4/60.5
69.6/73.3
(0.7,1]
99.7/99.8
85.1/96.8
98.5/99.5
Appendix
Table S9 : Foreground recall by initial confidence. Recall (%) in fixed p0 intervals after the same TAR refinement for each objective; cells list ten-dataset means for 1-shot/5-shot. All variants use λ=1 and T=0.5 . Objectives follow Table S8 .
RMS weights
1-shot
5-shot
Uniform
61.6
69.6
Reference
61.9
70.7
Appendix
Table S10 : Reference weights in RMS. Ten-dataset mean mIoU (%), without TAR. Both rows use prototype-response KL, fitted thresholds, and relative-gain selection.
Dataset
1-shot
5-shot
T=0.3
T=0.5
T=0.7
RMS threshold
T=0.3
T=0.5
T=0.7
RMS threshold
LVIS- 92i
44.5 (+1.3)
44.6 (+1.4)
43.1 (−0.1)
43.2
51.4 (+0.8)
53.4 (+2.8)
54.4 (+3.8)
50.6
COCO- 20i
56.6 (−1.4)
55.8 (−2.2)
53.9 (−4.1)
58.0
66.5 (−0.7)
67.3 (+0.1)
67.4 (+0.2)
67.2
FSS-1000
83.9 (−0.7)
84.7 (+0.1)
85.0 (+0.4)
84.6
87.0 (−0.6)
87.8 (+0.2)
88.3 (+0.7)
87.6
PASCAL- 5i
71.8 (−1.6)
70.3 (−3.1)
67.7 (−5.7)
73.4
88.1 (−0.1)
88.0 (−0.2)
87.3 (−0.9)
88.2
PASCAL-Part
54.4 (−1.1)
53.4 (−2.1)
51.0 (−4.5)
55.5
64.8 (−0.9)
65.6 (−0.1)
65.3 (−0.4)
65.7
Appendix
Table S11 : Thresholds on fixed RMS-selected probabilities. Foreground mIoU (%) on 133,962 matched episodes, without TAR. Parentheses report differences from the RMS threshold using displayed one-decimal scores; bold marks the best per dataset and shot, including ties.
Dataset
1-shot
5-shot
λ=1
λ=3
Min D
Relative gain
λ=1
λ=3
Min D
Relative gain
LVIS- 92i
42.5 (−0.7)
42.8 (−0.4)
42.5 (−0.7)
43.2
49.4 (−1.2)
51.1 (+0.5)
50.7 (+0.1)
50.6
COCO- 20i
57.5 (−0.5)
56.8 (−1.2)
56.7 (−1.3)
58.0
66.7 (−0.5)
67.3 (+0.1)
67.1 (−0.1)
67.2
FSS-1000
84.5 (−0.1)
84.5 (−0.1)
84.4 (−0.2)
84.6
87.6 (+0.0)
87.6 (+0.0)
87.6 (+0.0)
87.6
PASCAL- 5i
73.1 (−0.3)
72.2 (−1.2)
72.5 (−0.9)
73.4
87.8 (−0.4)
88.3 (+0.1)
88.3 (+0.1)
88.2
PASCAL-Part
55.4 (−0.1)
54.1 (−1.4)
54.2 (−1.3)
55.5
65.4 (−0.3)
65.5 (−0.2)
65.4 (−0.3)
65.7
Appendix
Table S12 : Branch selection in RMS. Foreground mIoU (%) on 133,962 matched episodes with fixed probabilities and threshold fits, without TAR. Parentheses subtract Relative gain using displayed scores; bold marks the best per setting, including ties.
Selection rule
1-shot
5-shot
Single branch: λ=1
61.5
70.2
Single branch: λ=3
61.0
70.6
Min D : λ∈{1,3}
61.0
70.5
Random λ∈{1,3}
61.2
70.4
50% correct (GT-assisted)
61.3
70.4
RMS: λ∈{1,3}
61.9
70.7
Appendix
Table S13 : Branch-selection controls. Ten-dataset mean mIoU (%) on 133,962 matched episodes, before TAR. Candidate probabilities and fitted thresholds are fixed; the random controls use λ∈{1,3} . Randomized controls average 20 fixed seeds.
Dataset
DINOv2-L/14
DINOv3-S/16
DINOv3-B/16
DINOv3-L/16
DINOv3-L/16
Debias ✓
Debias ✓
Debias ✓
Debias –
Debias ✓
Base
Full
Base
Full
Base
Full
Base
Full
Base
Full
LVIS- 92i
25.9/35.8
36.8 / 46.0
23.5/31.8
26.1 / 33.5
28.8/39.1
35.4 / 44.7
38.1/48.4
43.2 / 53.2
37.5/47.0
44.9 / 53.0
COCO- 20i
41.1/54.1
51.5 / 63.1
41.7/55.1
48.6 / 59.3
47.0/60.6
56.8 / 66.4
48.6/63.0
56.9 / 68.4
50.2/63.3
58.8 / 68.4
FSS-1000
76.4/80.5
82.5 / 85.9
80.7/85.6
86.7 / 89.0
80.7/86.1
86.8 / 89.9
82.9/86.8
87.6 / 90.2
81.3/86.2
86.4 / 89.5
PASCAL- 5i
60.0/75.6
68.5 / 83.3
64.2/81.2
71.6 / 84.7
68.9/84.5
75.6 / 88.3
60.6/83.2
67.6 / 86.9
66.6/85.2
73.8 / 88.9
Appendix
Table S14 : Backbone and debiasing results by dataset. Foreground mIoU (%) on 133,962 matched episodes per configuration; cells list 1-shot/5-shot. Base thresholds the first-stage p0 at 0.5 ; Full is RCA+RMS+TAR. Each pair shares the encoder, debias setting, episodes, and reference initialization. Bold marks the better score within each pair. Gains subtract displayed means.
Figure S2 : Ten-dataset mean comparison. ReSA uses DINOv2-L/14 and DINOv3-S/B/L/16; the no-debias control uses DINOv3-L/16. Table S14 gives the matched results. Methods without a complete ten-dataset mean are omitted. Gray indicates task-training overlap or possible overlap; these results are excluded from ranking. Circles/squares denote 1-shot/5-shot.
Dataset
1-shot
5-shot
No TAR
Unaligned
No evidence
Full TAR
No TAR
Unaligned
No evidence
Full TAR
LVIS- 92i
43.2 (−1.7)
44.8 (−0.1)
44.4 (−0.5)
44.9
50.6 (−2.4)
53.7 (+0.7)
52.5 (−0.5)
53.0
COCO- 20i
58.0 (−0.8)
58.3 (−0.5)
58.5 (−0.3)
58.8
67.2 (−1.2)
68.5 (+0.1)
68.1 (−0.3)
68.4
FSS-1000
84.6 (−1.8)
86.5 (+0.1)
86.6 (+0.2)
86.4
87.6 (−1.9)
89.7 (+0.2)
89.7 (+0.2)
89.5
PASCAL- 5i
73.4 (−0.4)
72.9 (−0.9)
73.5 (−0.3)
73.8
88.2 (−0.7)
88.7 (−0.2)
88.5 (−0.4)
88.9
PASCAL-Part
55.5 (−0.5)
55.6 (−0.4)
55.9 (−0.1)
56.0
65.7 (−0.6)
66.5 (+0.2)
66.3 (+0.0)
66.3
Appendix
Table S15 : Matched refinement controls. No TAR evaluates the RCA+RMS coarse mask; the other variants retain matched bands and pairwise terms. Foreground mIoU (%). Each setting covers 133,962 matched episodes. Parentheses give changes from Full TAR, calculated from the displayed one-decimal scores. Bold marks the highest displayed scores per dataset and shot, including ties.
Figure S3 : Boundary refinement across threshold deviations. The upper two rows show 1-shot/5-shot Boundary IoU gains in percentage points. Left: TAR minus unaligned CRF; right: TAR minus the coarse mask. Gains are averaged over matched episodes within each dataset, then over datasets. The lower panel shows the distribution of 133,690 valid-threshold episodes, normalized within each row. Groups I–IV share the d=∣T−0.5∣ intervals defined in the legend.
Branch setting
1-shot
5-shot
mIoU
Time
mIoU
Time
Single: λ=1
62.3
0.176
71.3
0.396
Single: λ=3
61.7
0.177
71.7
0.384
Dual: λ∈{1,3}
62.6
0.205
71.8
0.420
Three: λ∈{1,2,3}
62.6
0.210
71.7
0.450
Appendix
Table S16 : Complete-pipeline accuracy and time by branch count. mIoU (%) uses all 133,962 benchmark episodes; time (s/episode) uses the same 200 inputs and measurement protocol in Section G , on an H100. All four configurations include TAR. Bold marks the highest displayed mIoU per shot.
Method
1-shot
5-shot
Offline task training
FSSAM
0.100
0.167
SINE
0.300
0.830
SegIC
0.267
1.281
COSINE
0.502
1.068
LDIS-1
0.060
0.161
Appendix
Table S17 : Measured inference time (s/episode). H100 measurements use 100 episodes per shot, ten from each dataset, with complete inference timed as specified in Section G . Groups distinguish offline task training and test-time optimization. Bold marks the lowest time within each group and shot.
Comparison
1-shot
5-shot
Full vs. Base
+5.3[+4.1,+6.5]
+3.9[+3.1,+4.6]
RCA vs. R -only
+3.2[+2.4,+4.2]
+2.0[+1.4,+2.4]
Fitted T vs. 0.5
+1.6[+0.6,+2.5]
+0.0[−0.7,+0.6]
Gain vs. min. D
+0.9[+0.5,+1.2]
+0.2[+0.0,+0.4]
TAR vs. unaligned
+0.4[+0.2,+0.6]
+0.0[−0.2,+0.1]
Appendix
Table S18 : Paired benchmark-bootstrap intervals. Mean mIoU gain in points, followed by its 95% percentile interval. All pairs use matched configurations and episodes.
Figure 31
Figure S4 : Progressive effects of ReSA components. RCA recovers target regions missed by the initial prediction; RMS improves foreground selection; TAR refines the resulting contours. The successive predictions show how these stages contribute to more complete target masks and fewer extraneous regions. The figure presents 12 examples. Yellow boxes indicate regions enlarged consistently across prediction columns; IoUs are measured on the full query.
Figure 33
Figure S5 : Response constraints guide entropy-based adaptation. Adding the entropy term H to reference supervision can sharpen responses toward either foreground or background, amplifying distracting regions or suppressing target regions. The response constraint C guides this sharpening to retain the reference-specified foreground and suppress distracting responses. The figure presents 12 comparisons of R , R+H , and R+C+H , using the same initialization and optimization budgets, with λ=1 , T=0.5 , and no RMS or TAR. Probability maps share a common color scale; yellow boxes indicate the enlarged regions.
Figure 35
Figure S6 : Threshold alignment improves boundary refinement. Aligning the refinement scores with the selected threshold helps preserve target structures that unaligned CRF removes or distorts, improving the resulting boundaries. Matched crops highlight these differences at thin structures and object contours. The figure presents 12 examples, with both refiners using the same input probabilities and coarse mask. Yellow boxes indicate the enlarged regions; the reported gain is the full-image IoU difference between TAR and unaligned CRF.
Figure 37Figure 38Figure 39
Figure S7 : Qualitative comparisons with methods with and without offline task training. The comparisons show how ReSA retains the reference-specified target extent while rejecting nearby objects and surrounding regions. Whole-object and part examples highlight the role of reference guidance in distinguishing the desired foreground from visually similar content. The figure presents 24 five-shot examples from seven datasets. All methods receive the same query and five annotated references; one reference is shown. “ReSA − best” reports the IoU gain over the highest-scoring method among FSSAM, INSID3, and RSRM for each example.
Xi’an Institute of Optics and Precision Mechanics, Chinese Academy of Sciences · University of Chinese Academy of Sciences · Xi’an Jiaotong University +1