alphaFeedback

WorksComputer Science

From Visual Matching to Textual Conditioning: Cross-Domain Few-Shot Segmentation via Reference Inversion

AI contributions
Not recorded for this paper
View details

Abstract

Cross-Domain Few-Shot Segmentation (CD-FSS) aims to segment objects from unseen domains using only a few annotated references. Recent Segment Anything Model (SAM)-based methods have advanced CD-FSS, yet their reference-target visual matching is highly sensitive to target appearance variations. SAM3 introduces text-conditioned segmentation, enabling natural-language descriptions to guide segmentation across target images, but directly using the category name as the condition still yields unstable performance under severe domain shifts. We propose Reference Inversion for SAM3 (RI-SAM3) that leverages SAM3's large-scale vision-language pre-training to learn suitable textual tokens for each target category. RI-SAM3 comprises three core designs: (i) Bi-level Reference Inversion that learns complementary tokens before and after the frozen text encoder: the former remain anchored in SAM3's text space while the latter represent the category more flexibly; (ii) Layer-adaptive Textual Conditioning combines these tokens differently as object queries evolve across decoder layers; and (iii) Presence-aware Confidence Supervision that jointly supervises query confidence and target presence for reliable predictions. With SAM3 frozen, RI-SAM3 optimizes around 12K parameters only per category and it efficiently segments each target in a single forward pass with reusable textual conditioning without per-sample reference-target visual matching. Extensive experiments over multiple widely adopted benchmarks show that RI-SAM3 achieves superior performance consistently in CD-FSS tasks, together with strong robustness, efficiency, and generalization.

Introduction

Recent advances in semantic segmentation (Cheng et al. [6]; Kirillov et al. [26]; Wang et al. 2024) have achieved remarkable performance, yet most existing methods still rely heavily on large-scale annotated data. Such annotations are costly or impractical to obtain in data-scarce domains, including medical (Codella et al. [7]), satellite (Demir et al. [11]), and underwater imagery (Islam et al. [22]). Cross-Domain Few-Shot Segmentation (CD-FSS) (Lei et al. [27]) alleviates this burden by segmenting target categories from previously unseen domains using only a few annotated reference exemplars of the same categories. Conventional CD-FSS methods (Su et al. 2024; Nie et al. [37]; Fan et al. [14]; Tong et al. [53]) train a few-shot segmentation model on a large-scale source domain and then adapt it to each target domain. Although effective, this paradigm requires heavy source-domain training and target-domain adaptation, limiting its flexibility and efficiency.

To reduce this dependence, recent CD-FSS methods (Liu et al. [32]; Zhang et al. [62]; Xu et al. 2025; Nie et al. [38]) match reference and target images using the transferable dense features of DINOv2 (Oquab et al. [40]), and convert the resulting correspondences into geometric prompts that guide SAM (Kirillov et al. [26]) to segment the target images. Although reducing training cost, this paradigm exhibits weak generalization across target images of the same category. As illustrated in Figure 1 (Left), GF-SAM (Zhang et al. [62]) exhibits substantial variations in prediction quality across target images, even when using the same reference image. This variation suggests that visual matching depends on the appearance similarity between each reference and target image, rather than representing the target category consistently across images. Moreover, the reference image remains necessary during inference, as visual matching must be conducted for every target image. These limitations motivate us to seek a category representation that can be reused across target images.

Performance comparison of GF-SAM, the category-name prompt baseline, and RI-SAM3 across Chest X-Ray and DeepGlobe

Figure 1. Motivation for Reference Inversion for SAM3 (RI-SAM3). Left: Using the same reference image, GF-SAM [62] exhibits substantial IoU variations across different target images, while manually specified text prompts produce low and unstable results under severe domain shifts. Our proposed RI-SAM3 instead inverts annotated references into a reusable textual condition for inference targets. Right: RI-SAM3 achieves higher mIoU (↑\uparrow) and a lower standard deviation of per-image IoU (↓\downarrow) than GF-SAM and the category-name prompt baseline, demonstrating improved accuracy and stability.

Natural language offers such a representation by describing categories without relying on visual references (Radford et al. [43]). SAM3 (Carion et al. [2]) further supports text-conditioned segmentation, allowing these language descriptions to guide target segmentation. A straightforward attempt is to use category names as SAM3’s textual prompts. However, as shown in Figure 1 (Left), this strategy yields low average performance and substantial variations across targets of the same category. These results indicate that category-name prompts still yield poor generalization across targets under severe domain shifts. Nevertheless, SAM3’s large-scale vision-language pre-training provides a text space aligned with visual categories, motivating us to seek reusable tokens that represent each target category within this text space.

Textual inversion for personalized visual generation (Gal et al. 2022) ... et al. 2023) offers a way to obtain such a representation by inverting new textual tokens from a few references. Motivated by its success, we propose Reference Inversion for SAM3 (RI-SAM3), which converts annotated references into reusable soft textual tokens. The references are used only during inversion and discarded during inference, replacing per-sample reference-target visual matching with reusable textual conditioning. To make the inversion effective under substantial domain shifts, RI-SAM3 incorporates three designs. First, Bi-level Reference Inversion learns complementary tokens before and after the frozen text encoder: the former remain anchored in SAM3’s text space, while the latter represent the target category more flexibly. Second, as object queries evolve through the decoder, Layer-adaptive Textual Conditioning combines these tokens differently across layers. Third, Presence-aware Confidence Supervision jointly supervises query confidence and target presence to improve prediction reliability. With the SAM3 backbone frozen, RI-SAM3 optimizes only approximately 12K parameters per category. The inverted tokens then condition SAM3 to segment each target image in a single forward pass, without references or per-sample visual matching during inference. As shown in Figure 1 (Right), RI-SAM3 achieves higher mIoU and lower standard deviation across target images than GF-SAM and the category-name baseline, demonstrating improved accuracy and stability. Extensive experiments across widely adopted benchmarks further demonstrate substantial improvements over existing CD-FSS methods, together with strong robustness, efficiency, and generalization.

The contributions of this work can be summarized in three aspects: First, we revisit reference-target visual matching in CD-FSS and identify its limited generalization across targets of the same category, as predictions are sensitive to variations in target appearance. Second, we propose RI-SAM3, a lightweight Reference Inversion framework that converts annotated references into reusable soft textual tokens through three complementary designs. With SAM3 frozen, RI-SAM3 optimizes only approximately 12K parameters per category and conditions each target prediction in a single forward pass without references or visual matching. Third, extensive experiments show that RI-SAM3 achieves strong performance on CD-FSS benchmarks while exhibiting robustness to different reference images, high computational efficiency, and generalization to related few-shot tasks.

Cross-Domain Few-Shot Segmentation

Cross-Domain Few-Shot Segmentation (CD-FSS) aims to segment target objects conditioned on a few annotated references under significant domain shifts [55, 52, 4, 51, 37, 8] (Lu et al. 2021; Wu et al. 2024; Zhu et al. 2025). Early methods [27] (Fu et al. 2024) usually follow a two-stage paradigm, training on a large-scale source domain and then adapting to each target domain through dynamic refinement [13], knowledge transfer [21], frequency disentanglement [53], or lightweight adaptation [14] (Su et al. 2024). With the advent of vision foundation models [26, 40, 46, 45], recent studies [32, 62, 64, 50, 31, 9, 41, 38] (Xu et al. 2025; Ma et al. 2026) typically conduct reference-target visual matching and convert the correspondences into geometric prompts for SAM. However, such correspondences remain specific to individual reference-target pairs and can be sensitive to target appearance variations. SAM3 [2] introduces text-conditioned segmentation, which can segment all target images with natural language prompts. Motivated by this capability, we replace pairwise visual matching with textual conditioning using reusable soft reference tokens to segment all target images.

SAM Adaptation for Downstream Tasks

Despite their strong promptable segmentation ability, SAM-family models ([26, 45]) often require adaptation to specialized domains, including medical ([5] (Ma et al. 2024; Wu et al. 2025)) and satellite imagery ([28, 12, 28]). Existing approaches adapt SAM using large-scale domain-specific annotations (Ma et al. 2024), lightweight trainable modules ([5] (Ke et al. 2023)), or few-shot target-domain tuning ([59]). These methods primarily adapt the model representation or mask decoder to a downstream domain. In contrast, we keep SAM3 frozen and adapt its input prompts by learning only reference tokens and lightweight layer-wise coefficients.

Textual Inversion for Visual Generation

Textual inversion ([16]) is a representative approach for customized content generation with pre-trained text-to-image models ([42]). Given a few references of a specific subject, it learns new tokens in the text space, enabling this subject to be re-generated in novel scenes. Subsequent personalization methods ([47]) have extended this idea to multiple subjects ([24]), video motions ([20]), and 3D assets ([44]). Like customized content generation, target categories under substantial domain shifts cannot be fully represented by manually specified language prompts. Inspired by the success of textual inversion, we introduce reference inversion to transform annotated references into reusable reference tokens that condition SAM3 to segment any target image of the same category.

Preliminary Study

Problem Formulation

Cross-Domain Few-Shot Segmentation (CD-FSS) aims to segment target objects from previously unseen domains with only a few annotated references. In the KK-shot setting, a reference set Sc={(Iri,Mri)}i=1KS_c = \{(I_r^i, M_r^i)\}_{i=1}^{K} is provided for category cc, where IriI_r^i and MriM_r^i denote the ii-th reference image and its ground-truth mask, respectively. Given a target image ItI_t of the same category, the goal is to predict its segmentation mask MtM_t using the available reference set ScS_c.

Reference-Target Visual Matching. Previous CD-FSS methods generally condition each target prediction directly on the references: M^t=GΦ(It,Sc)\hat{M}_t = G_{\Phi}(I_t, S_c), where GΦG_{\Phi} denotes a CD-FSS model. Regardless of the underlying architecture, these methods typically match reference and target features through visual prototypes, feature correlations, or dense correspondences. Consequently, each target prediction depends directly on ScS_c, requiring reference-target visual matching to be performed for every ItI_t. Therefore, such visual similarity is sensitive to appearance variations (refer to Figure 1).

Reference Inversion. In this paper, we reformulate the role of references ScS_c in CD-FSS. Instead of performing visual matching between ScS_c and each ItI_t, we invert the references into a reusable textual condition Tc∗T_c^* that can be shared across target images. Let FΘF_{\Theta} denote the pre-trained SAM3 with frozen parameters Θ\Theta. Given ScS_c, we obtain Tc∗T_c^* while keeping Θ\Theta frozen. After inversion, ScS_c is discarded, and target prediction is performed as M^t=FΘ(It;Tc∗)\hat{M}_t = F_{\Theta}(I_t; T_c^*). This formulation decouples predictions from target inference, allowing Tc∗T_c^* to be reused across all target images without further access to ScS_c. Importantly, this reformulation does not modify the standard CD-FSS reference-target construction; it only replaces pairwise visual matching with a reusable conditioning representation.

Segment Anything Model 3

Architecture. Segment Anything Model 3 (SAM3) ([2]) extends the Segment Anything family ([26, 45]) to promptable concept segmentation, where concept prompts, such as category names, specify all matching instances to be segmented. For text-conditioned segmentation, SAM3 encodes the text prompt and input image into textual and visual tokens, respectively. Its mask decoder follows a DETR-style architecture ([3]), progressively refining object-query tokens through self-attention, query-text cross-attention, and query-visual cross-attention. Each decoder layer predicts a classification score and a box offset for each object-query token, while a segmentation head decodes the final query tokens into instance masks. SAM3 further introduces a global presence token to estimate whether the prompted concept appears in the image, with its presence score modulating the query-level classification scores.

Design Implications. SAM3’s predictions depend critically on how its textual prompt represents the target category. Category names provide only generic descriptions, motivating us to invert references into complementary word- and concept-level tokens. Moreover, visual representations at different depths encode complementary semantic information ([17]), while stacked decoder layers progressively refine object queries ([3]). Using an identical textual condition across all decoder layers may therefore be suboptimal, motivating layer-wise combinations of the two tokens. Finally, because mask confidence depends jointly on query and presence scores, both require reliable supervision under domain shifts. These properties motivate our Bi-level Reference Inversion, Layer-adaptive Textual Conditioning, and Presence-aware Confidence Supervision.

Method

As illustrated in Figure 2, our Reference Inversion framework transforms annotated references into a reusable textual representation while keeping SAM3 frozen. Bi-level Reference Inversion optimizes a reference word embedding ew∗e_w^* before the text encoder and the reference concept tokens zc∗z_c^* after it. Layer-adaptive Textual Conditioning combines the encoded reference word tokens zw∗z_w^* and zc∗z_c^* with layer-wise fusion coefficients αl\alpha_l to construct the bi-level reference tokens Tc∗T_c^* for conditioning different decoder layers. Presence-aware Confidence Supervision further improves prediction reliability by supervising mask quality, query classification, and target presence. Once inverted, Tc∗T_c^* is reused across target images without further access to the annotated references.

Overview of the RI-SAM3 framework

Figure 2. Overview of our proposed RI-SAM3 framework. Bi-level Reference Inversion (BRI) learns reference word tokens zw∗z_w^* and reference concept tokens zc∗z_c^* from annotated references, collectively termed inverted reference tokens. Layer-adaptive Textual Conditioning (LTC) combines them with layer-specific fusion coefficients αl\alpha_l to produce the bi-level reference tokens TclT_c^l for conditioning frozen SAM3. Presence-aware Confidence Supervision (PCS) jointly supervises query-level classification and global presence scores. Once learned, Tc∗T_c^* is reused for target segmentation without references or visual matching.

Bi-level Reference Inversion

Textual inversion learns a pseudo-word embedding at the input of a frozen text encoder [16]. Passing the learned pseudo-word embedding through the text encoder anchors the resulting tokens to the pre-trained language space, but may limit its flexibility in capturing target-category appearance under severe domain shifts. In contrast, directly optimizing the tokens after the text encoder provides greater flexibility but lacks such a language anchor. We therefore perform Reference Inversion at both levels.

Let Etext\mathcal{E}_{\text{text}} denote the frozen text encoder of SAM3. We introduce a learnable reference word embedding ewe_w at its input and optimize it using the annotated references. The frozen text encoder maps ewe_w to the reference word tokens:

zw∗=Etext(ew∗).(1)z_w^* = \mathcal{E}_{\text{text}}(e_w^*). \tag*{(1)}

Because zw∗z_w^* is obtained through the frozen text encoder, the resulting tokens remain anchored in SAM3’s pre-trained text space. Meanwhile, we introduce reference concept tokens zc∗z_c^* directly after the text encoder. Without being constrained by the text encoding process, zc∗z_c^* can more flexibly represent the target-category concept specified by the references. They are independently optimized using the annotated references:

ew∗=arg min⁡ew1K∑i=1KLref(FΘ(Iri;Eext(ew)),Mri),(2)e_w^* = \underset{e_w}{\operatorname{arg\,min}} \frac{1}{K} \sum_{i=1}^{K} \mathcal{L}_{\mathrm{ref}}\left(\mathcal{F}_{\Theta}\left(I_r^i; \mathcal{E}_{\text{ext}}(e_w)\right), M_r^i\right), \tag*{(2)}
zc∗=arg min⁡zc1K∑i=1KLref(FΘ(Iri;zc),Mri),(3)z_c^* = \underset{z_c}{\operatorname{arg\,min}} \frac{1}{K} \sum_{i=1}^{K} \mathcal{L}_{\mathrm{ref}}\left(\mathcal{F}_{\Theta}\left(I_r^i; z_c\right), M_r^i\right), \tag*{(3)}

where Lref\mathcal{L}_{\mathrm{ref}} represents supervision introduced below. The resulting reference word tokens zw∗=Etext(ew∗)z_w^* = \mathcal{E}_{\text{text}}(e_w^*) and reference concept tokens zc∗z_c^* are collectively referred to as the inverted reference tokens.

Layer-adaptive Textual Conditioning

SAM3 progressively refines its object-query tokens through LL decoder layers, each consisting of query self-attention, query-text cross-attention, and query-visual cross-attention. Since the object queries evolve across decoder layers, using the same textual condition throughout the decoder may be suboptimal. We therefore introduce Layer-adaptive Textual Conditioning, which adaptively combines the two inverted reference tokens for each decoder layer. Specifically, the bi-level reference tokens for the ll-th layer are constructed as:

Tcl=(1−αl)zw∗+αlzc∗,αl∈[0,1],(4)T_c^l = (1-\alpha_l)z_w^* + \alpha_l z_c^*, \qquad\alpha_l \in[0,1], \tag*{(4)}

where αl\alpha_l is the learnable fusion coefficient of the ll-th decoder layer. Omitting residual connections, normalization, and feed-forward layers for clarity, the object-query tokens are updated as:

Q‾l=SelfAttn⁡l(Ql−1),(5)\overline{Q}_l = \operatorname{SelfAttn}_l(Q_{l-1}), \tag*{(5)}
Q~l=CrossAttn⁡ltext(Q‾l,Tcl),(6)\widetilde{Q}_l = \operatorname{CrossAttn}_l^{\text{text}}(\overline{Q}_l,T_c^l), \tag*{(6)}
Ql=CrossAttn⁡lvis(Q~l,v),(7)Q_l = \operatorname{CrossAttn}_l^{\text{vis}}(\widetilde{Q}_l,v), \tag*{(7)}

where vv denotes the visual tokens of the input image. In this way, each decoder layer receives a textual condition adapted to its current object-query tokens before interacting with the visual tokens.

With the inverted reference tokens fixed, we optimize the layer-wise fusion coefficients: α={αl}l=1L\alpha= \{\alpha_l\}_{l=1}^{L} using the annotated references:

α∗=arg min⁡α1K∑i=1KLref(FΘ(Iri;Tc(α)),Mri),(8)\alpha^* = \underset{\alpha}{\operatorname{arg\,min}} \frac{1}{K} \sum_{i=1}^{K} \mathcal{L}_{\mathrm{ref}}\left(\mathcal{F}_{\Theta}\left(I_r^i;T_c(\alpha)\right),M_r^i\right), \tag*{(8)}

where Tc(α)={Tcl}l=1LT_c(\alpha)=\{T_c^l\}_{l=1}^{L} collects the layer-specific bi-level reference tokens. Once optimized, α∗\alpha^* remains fixed and is shared across all target images of category cc.

Presence-aware Confidence Supervision

SAM3 determines the confidence of each predicted mask using both its query-level classification score and the global presence presence score. Under substantial domain shifts, conventional mask supervision does not directly ensure the reliability of either score. We therefore introduce Presence-aware Confidence Supervision to align query confidence with mask quality and supervise target presence. Let AjA_j and sjs_j denote the mask and classification logits of the jj-th object query, respectively, and let sps_p denote the global presence logit. We first apply standard BCE and Dice losses to the reference prediction M^r=max⁡jσ(Aj)\hat{M}_r = \max_j \sigma(A_j):

Lmask=LBCE(M^r,Mr)+LDice(M^r,Mr).(9)\mathcal{L}_{\mathrm{mask}} = \mathcal{L}_{\mathrm{BCE}}(\hat{M}_r, M_r) + \mathcal{L}_{\mathrm{Dice}}(\hat{M}_r, M_r). \tag*{(9)}

For each query, we use its soft mask IoU as the quality target:

qj=IoU⁡(σ(Aj),Mr),j∗=arg⁡max⁡jqj,(10)q_j = \operatorname{IoU}(\sigma(A_j), M_r), \qquad j^* = \arg\max_j q_j, \tag*{(10)}

where qjq_j is recomputed from the current mask prediction at each iteration and detached during backpropagation. Presence-aware Confidence Supervision then consists of quality, ranking, and presence supervision:

Lquality=1Nq∑j=1NqLBCE(sj,qj),(11)\mathcal{L}_{\mathrm{quality}} = \frac{1}{N_q}\sum_{j=1}^{N_q}\mathcal{L}_{\mathrm{BCE}}(s_j, q_j), \tag*{(11)}
Lranking=max⁡(0,δ−sj∗+max⁡j≠j∗sj),(12)\mathcal{L}_{\mathrm{ranking}} = \max(0, \delta- s_{j^*} + \max_{j\ne j^*} s_j), \tag*{(12)}
Lpresence=LBCE(sp,1),(13)\mathcal{L}_{\mathrm{presence}} = \mathcal{L}_{\mathrm{BCE}}(s_p, 1), \tag*{(13)}

where δ\delta is the ranking margin. Following the standard CD-FSS protocol, the target category is present in every reference and target image; therefore, the presence label is always positive. Further discussion is provided in the appendix. We combine all of these losses to optimize both the inverted reference tokens and the layer-wise fusion coefficients:

Lref=Lmask+λ(Lquality+Lranking+Lpresence).(14)\mathcal{L}_{\mathrm{ref}} = \mathcal{L}_{\mathrm{mask}} + \lambda(\mathcal{L}_{\mathrm{quality}} + \mathcal{L}_{\mathrm{ranking}} + \mathcal{L}_{\mathrm{presence}}). \tag*{(14)}

Overall, Reference Inversion is optimized in two stages. We first learn ew∗e_w^* and zc∗z_c^* independently and then fix the resulting inverted reference tokens to optimize the layer-wise fusion coefficients. Throughout this process, SAM3 remains frozen and only approximately 12K category-specific parameters are learned. Once optimized, Tc∗T_c^* is reused across target images, enabling single-pass inference without references or visual matching.

Experiment

Dataset

We conduct extensive experiments on four Cross-Domain Few-Shot Segmentation (CD-FSS) datasets spanning medical images [7, 54, 1, 23], satellite images [11], and underwater scenes [22]. ISIC2018 [7, 54] consists of dermoscopic images for skin lesion analysis and covers three lesion categories. Chest X-Ray [1, 23] is a dataset collected for tuberculosis screening. DeepGlobe [11] is a satellite image dataset containing six terrain categories, including urban, agriculture, rangeland, forest, water, and barren areas. Following PATNet (Lei et al. [27], we split the original images into small patches for evaluation. SUIM (Islam et al. [22] is an underwater dataset comprising six object categories, including fish, plants, divers, robots, ruins, and rocks.

Implementation Details

We adopt the official pre-trained SAM3 model (Carion et al. [2]) and keep it frozen. All images are processed at a resolution of 1008×10081008 \times1008. For each target category, the soft textual representation is learned solely from the annotated references. During inference, the reference image and mask are discarded, and each target image is processed with a single SAM3 forward pass conditioned on the learned textual representation. We report mean Intersection over Union (mIoU) as the evaluation metric. We strictly follow the standard evaluation protocols and dataset splits adopted by prior CD-FSS studies. RI-SAM3 only changes how the given references are utilized: instead of matching them with individual target images, it inverts the same reference set into a reusable textual condition.

Comparison with State-of-the-Art Methods

We compare our proposed RI-SAM3 with conventional ResNet-/ViT-based methods ([14, 27, 53, 19, 52, 33, 39] (Su et al. 2024; Li et al. 2025b)) and Vision Foundation Model (VFM)-based methods ([63, 32, 61, 38, 62, 10, 48] (He et al. 2024)). As shown in Table 1, RI-SAM3 achieves the best result in seven evaluation settings compared with VFM-based methods. On ISIC, our method improves the previous best VFM-based results by 9.2% and 7.5% under the 1-shot and 5-shot settings, respectively. Consistent gains are observed on Chest X-Ray, where it surpasses APSeg by 6.4% and 6.5%, and on SUIM, where it exceeds INSIS3D by 8.3% and 16.4%. On DeepGlobe, RI-SAM3 achieves the best 1-shot result and remains competitive in the 5-shot setting. These results demonstrate the advantage of replacing visual matching with a representative textual condition. Our method also compares favorably with conventional ResNet-/ViT-based approaches. It reaches 90.5% and 91.0% mIoU on Chest X-Ray, outperforming the strongest results by 6.6% and 3.9%. Substantial improvements are also achieved on SUIM, demonstrating effectiveness under challenging underwater domain shifts. Moreover, RI-SAM3 obtains the best 5-shot result on ISIC and remains competitive on DeepGlobe. Finally, the 5-shot performance consistently exceeds its 1-shot counterpart across all datasets. This trend suggests that additional reference images provide more comprehensive information, enabling the learned textual condition more representative. As Figure 3 shows, RI-SAM3 achieves accurate segmentation on CD-FSS datasets.

MethodVenueISIC 1-shotISIC 5-shotChest X-Ray 1-shotChest X-Ray 5-shotDeepGlobe 1-shotDeepGlobe 5-shotSUIM 1-shotSUIM 5-shot
Conventional ResNet-/ViT-based Methods
ISAICCV 202537.256.183.486.344.352.744.1–
DR-AdapterCVPR 202440.848.982.482.341.350.1––
PATNetECCV 202241.253.666.670.237.943.032.140.2
APMNeurIPS 202441.751.278.382.840.944.9––
ABCDFSSCVPR 202445.753.379.881.442.649.035.141.3
SDRCICML 202546.655.082.984.843.246.8––
DFNICML 2025 Spotlight50.458.583.287.139.547.7––
LoECCVPR 202552.962.483.984.142.151.5––
IFACVPR 202466.369.874.074.650.658.8––
DATOCVPR 202568.870.379.681.151.159.3––
Vision Foundation Model-based Methods
PerSAMICLR 202423.9–––31.4–––
MatcherICLR 202438.635.066.866.348.150.937.941.4
APSegCVPR 202445.454.084.184.535.940.0––
TAVParXiv 202454.9–––46.1–––
CPSarXiv 202651.356.670.070.246.049.842.848.8
GF-SAMNeurIPS 2024 Spotlight48.755.247.647.449.557.738.342.9
PerSAM-F*ICLR 202420.5–38.7–46.5–10.3–
VLP-SAM*arXiv 202534.845.954.759.148.152.416.926.9
INSID3CVPR 2026 Oral54.463.978.880.1––54.961.7
RI-SAM3*–64.171.490.591.051.855.863.278.1

Table 1. Quantitative comparison between the proposed RI-SAM3 and existing methods on four CD-FSS benchmarks in mIoU (%). Results are taken from the original papers whenever available. Methods marked by * are averaged over five random seeds. The best result within each method group is highlighted in bold.

Qualitative segmentation results of RI-SAM3 on samples from four datasets

Figure 3. Qualitative segmentation results (red mask) of RI-SAM3 on samples from four datasets.

Ablation Study

All variants in Table 2 use the same frozen SAM3 backbone, ensuring that their performance differences arise from the incorporated designs rather than backbone changes. Directly prompting SAM3 with category names yields limited performance under substantial domain shifts. Bi-level Reference Inversion (BRI) substantially improves performance on ISIC, Chest X-Ray, and SUIM by 44.7%, 64.9%, and 38.3%, respectively, demonstrating that the inverted textual condition is more representative than category names. Layer-adaptive Textual Conditioning further improves performance on ISIC, DeepGlobe, and SUIM by 4.9%, 20.1%, and 4.4%, respectively, demonstrating the benefit of adaptively combining the inverted reference tokens across decoder layers. Finally, Presence-aware Confidence Supervision (PCS) consistently provides additional gains of 1.0%-7.9% by jointly supervising query confidence and target presence. Overall, the complete method consistently improves the SAM3 baseline prompted with category names by large margins across the four datasets, confirming the effectiveness and complementarity of the three designs. The appendix provides controlled comparisons with conventional textual inversion, visual prompt with SAM3, and GF-SAM using the frozen SAM3, fine-grained ablations of BRI and PCS, an analysis of shared versus layer-adaptive textual condition, and a non-empty prediction control. It also evaluates multiple textual initializations to verify that the improvements do not rely on carefully selected category labels.

Incorporated designISICChest X-RayDeepGlobeSUIM
SAM3 + category-name10.224.421.516.1
SAM3 + BRI54.989.323.854.4
+ LTC59.889.543.958.8
+ PCS64.190.551.863.2

Table 2. Ablation studies of proposed components of RI-SAM3 under the 1-shot setting (mIoU (%)). All variants use the same pre-trained SAM3 with frozen parameters.

Robustness to Reference Image Selection

In our RI-SAM3, the textual representations are inverted from the selected reference exemplar and subsequently reused across all target images. Robustness to reference image selection is therefore particularly important. We evaluate five random reference selections and compare with PerSAM-F [63] and VLP-SAM [48], which respectively learn mask aggregation weights and multimodal reference prompts. As shown in Table 3, RI-SAM3 achieves the highest mean performance and the lowest standard deviation across all datasets. The improvement is especially pronounced on Chest X-Ray and DeepGlobe, where our standard deviations are only 0.6 and 2.9. Consistent improvements are also observed on ISIC and SUIM. These results demonstrate that RI-SAM3 is substantially less sensitive to the choice of reference image, supporting reliable textual inversion across different reference selections. We also evaluate the robustness of our RI-SAM3 to different hyperparameters in the appendix.

MethodISICChest X-RayDeepGlobeSUIM
PerSAM-F20.5±6.320.5 \pm6.338.7±7.738.7 \pm7.746.5±10.546.5 \pm10.510.3±5.110.3 \pm5.1
VLP-SAM34.8±5.034.8 \pm5.054.7±14.554.7 \pm14.548.1±16.148.1 \pm16.116.9±6.316.9 \pm6.3
RI-SAM364.1±4.864.1 \pm4.890.5±0.690.5 \pm0.651.8±2.951.8 \pm2.963.2±3.463.2 \pm3.4

Table 3. Stability comparison over five random reference selections, reported as mean mIoU (%) ± standard deviation.

Efficiency Analysis

Table 4 compares the efficiency of conventional and SAM-based CD-FSS methods. For a fair comparison, all efficiency evaluations are conducted on the same datasets under identical environments. Conventional methods, including PATNet and IFA, require over 500 minutes of preparation, resulting in total runtimes exceeding 540 minutes. In contrast, our method acquires a reusable textual condition in only 2 minutes while keeping SAM3 frozen and optimizing approximately 12K parameters. The detailed calculation of learnable parameters is provided in the appendix. Compared with SAM-based Matcher and GF-SAM, which require 41 and 8 minutes for inference, respectively, our method completes inference in only 2 minutes. Its total runtime is therefore only 4 minutes, while its model size is reduced from 945M to 840M parameters. Moreover, our method requires only 3.7×10123.7 \times10^{12} FLOPs, less than the 8.6×10128.6 \times10^{12} and 8.4×10128.4 \times10^{12} FLOPs required by Matcher and GF-SAM. These results demonstrate that RI-SAM3 enables lightweight reference inversion and efficient text-conditioned inference.

ResNet-based Methods
MethodPreparationInferenceTotal
PATNet5385543
IFA5415545
SAM-based Methods
MethodPrep.Inf.TotalModel size (M)FLOPs (T)
Matcher–41419458.6
GF-SAM–889458.4
RI-SAM32248403.7

Table 4. Efficiency comparison under the 1-shot CD-FSS setting. Preparation refers to the optimization performed before target inference, including source training, target adaptation, or concept acquisition, depending on the method.

Generalization across Tasks

Beyond CD-FSS, we evaluate the generalization of our proposed RI-SAM3 on three In-Domain Few-Shot Segmentation benchmarks and two One-Shot Part Segmentation benchmarks, detailed in the appendix. As shown in Table 5, our method consistently outperforms all Vision Foundation Model-based approaches across all settings. The complete comparison under both 1-shot and 5-shot settings is provided in the appendix. Compared with the strongest competing results, it improves PASCAL-5i by 8.3% and 1.4%, COCO-20i by 12.2% and 7.6%, and FSS-1000 by 3.5% and 2.4% under the 1-shot and 5-shot settings, respectively. It also surpasses GF-SAM by 13.1% on PASCAL-Part and 9.5% on PACO-Part. Qualitative examples in the appendix further illustrate accurate segmentation at both object and part levels. These consistent improvements across object- and part-level segmentation demonstrate that RI-SAM3 learns category-level representations at different semantic granularities, indicating strong generalization beyond CD-FSS.

MethodIn-Domain FSSOne-Shot Part Seg.
Pasc.-5iCOCO-20iFSS.PASC.-PartPACO-Part
PerSAM43.123.071.232.522.5
PerSAM-F48.523.575.632.922.7
Matcher68.152.787.042.934.7
VRP-SAM71.953.9–––
GF-SAM72.158.788.044.536.3
CPS–49.281.7––
INSID3–57.6–––
RI-SAM380.470.991.557.645.8

Table 5. Generalization under the 1-shot setting in mIoU (%). The best results are highlighted in bold.

Conclusion

In this work, we revisited reference-target visual matching in CD-FSS and highlighted its sensitivity to target appearance variations. We proposed RI-SAM3, which replaces per-sample visual matching with reusable textual tokens inverted from annotated references. Bi-level Reference Inversion learns complementary token bases before and after the frozen text encoder, Layer-adaptive Textual Conditioning adapts their combination across decoder layers, and Presence-aware Confidence Supervision improves prediction reliability. With SAM3 frozen, RI-SAM3 optimizes only approximately 12K parameters per category and segments each target in a single forward pass without reference images. Extensive experiments demonstrate strong performance, robustness, computational efficiency, and generalization to related tasks.

References

  1. [1]Candemir, S.; Jaeger, S.; Palaniappan, K.; Musco, J. P.; Singh, R. K.; Xue, Z.; Karargyris, A.; Antani, S.; Thoma, G.; and McDonald, C. J. 2013. Lung segmentation in chest radiographs using anatomical atlases with nonrigid registration. TMI.DOI
  2. [2]Carion, N.; Gustafson, L.; Hu, Y.-T.; Debnath, S.; Hu, R.; Suris, D.; Ryali, C.; Alwala, K. V.; Khedr, H.; Huang, A.; et al. 2026. Sam 3: Segment anything with concepts. In ICLR.arxiv.org/abs/2511.16719
  3. [3]Carion, N.; Massa, F.; Synnaeve, G.; Usunier, N.; Kirillov, A.; and Zagoruyko, S. 2020. End-to-end object detection with transformers. In ECCV.arxiv.org/abs/2005.12872
  4. [4]Chen, H.; Dong, Y.; Lu, Z.; Yu, Y.; and Han, J. 2024. Pixel Matching Network for Cross-Domain Few-Shot Segmentation. In WACV.DOI
  5. [5]Chen, T.; Zhu, L.; Ding, C.; Cao, R.; Wang, Y.; Li, Z.; Sun, L.; Mao, P.; and Zhang, Y. 2023. SAM Fails to Segment Anything?–SAM-Adapter: Adapting SAM in Underperformed Scenes: Camouflage, Shadow, Medical Image Segmentation, and More. arXiv preprint arXiv:2304.09148.arxiv.org/abs/2304.09148
  6. [6]Cheng, B.; Misra, I.; Schwing, A. G.; Kirillov, A.; and Girdhar, R. 2022. Masked-attention mask transformer for universal image segmentation. In CVPR.arxiv.org/abs/2112.01527
  7. [7]Codella, N.; Rotemberg, V.; Tschandl, P.; Celebi, M. E.; Dusza, S.; Gutman, D.; Helba, B.; Kalloo, A.; Liopırys, K.; Marchetti, M.; et al. 2019. Skin lesion analysis toward melanoma detection 2018: A challenge hosted by the international skin imaging collaboration (isic). arXiv preprint arXiv:1902.03368.arxiv.org/abs/1902.03368
  8. [8]Cong, R.; Wang, A.; Wan, B.; Zhang, C.; Zhou, X.; and Zhang, W. 2026. Divide-and-conquer decoupled network for cross-domain few-shot segmentation. In AAAI.
  9. [9]Cuttano, C.; Trivigno, G.; Averta, G.; and Masone, C. 2025. SANSA: Unleashing the Hidden Semantics in SAM2 for Few-Shot Segmentation. In NeurIPS.arxiv.org/abs/2505.21795
  10. [10]Cuttano, C.; Trivigno, G.; Reich, C.; Cremers, D.; Masone, C.; and Roth, S. 2026. INSID3: Training-Free In-Context Segmentation with DINOv3. In CVPR.arxiv.org/abs/2603.28480
  11. [11]Demir, I.; Koperski, K.; Lindenbaum, D.; Pang, G.; Huang, J.; Basu, S.; Hughes, F.; Tuia, D.; and Raskar, R. 2018. Deepglobe 2018: A challenge to parse the earth through satellite images. In CVPRW.DOI
  12. [12]Ding, L.; Zhu, K.; Peng, D.; Tang, H.; Yang, K.; and Bruzzone, L. 2024. Adapting segment anything model for change detection in VHR remote sensing images. TGRS.DOI
  13. [13]Fan, H.; Fan, Q.; Paganucco, M.; and Song, Y. 2023. DAR-Net: Bridging Domain Gaps in Cross-Domain Few-Shot Segmentation with Dynamic Adaptation. arXiv preprint arXiv:2312.04813.arxiv.org/abs/2312.04813
  14. [14]Fan, Q.; Liu, K.; Liu, N.; Cholakkal, H.; Anwer, R. M.; Li, W.; and Gao, Y. 2025. Adapting In-Domain Few-Shot Segmentation to New Domains without Retraining. In ICCV.arxiv.org/abs/2504.21414
  15. [16]Gal, R.; Alaluf, Y.; Atzmon, Y.; Patashnik, O.; Bermano, A. H.; Chechik, G.; and Cohen-Or, D. 2023. An image is worth one word: Personalizing text-to-image generation using textual inversion. In ICLR.arxiv.org/abs/2208.01618
  16. [17]Hariharan, B.; Arbeláez, P.; Girshick, R.; and Malik, J. 2015. Hypercolumns for object segmentation and fine-grained localization. In CVPR.
  17. [19]Herzog, J. 2024. Adapt Before Comparison: A New Perspective on Cross-Domain Few-Shot Segmentation. In CVPR.arxiv.org/abs/2402.17614
  18. [20]Huang, C.-P.; Wu, Y.-S.; Chung, H.-K.; Chang, K.-P.; Yang, F.-E.; and Wang, Y.-C. 2025. Videomage: Multi-subject and motion customization of text-to-video diffusion models. In CVPR.arxiv.org/abs/2503.21781
  19. [21]Huang, X.; Zhu, C.; and Chen, W. 2023. Restnet: Boosting cross-domain few-shot segmentation with residual transformation network. In BMVC.arxiv.org/abs/2308.13469
  20. [22]Islam, M. J.; Edge, C.; Xiao, Y.; Luo, P.; Mehtaz, M.; Morse, C.; Enan, S. S.; and Sattar, J. 2020. Semantic segmentation of underwater imagery: Dataset and benchmark. In IROS.arxiv.org/abs/2004.01241
  21. [23]Jaeger, S.; Karargyris, A.; Candemir, S.; Folio, L.; Siegelman, J.; Callaghan, F.; Xue, Z.; Palaniappan, K.; Singh, R. K.; Antani, S.; et al. 2013. Automatic tuberculosis screening using chest radiographs. TMI.DOI
  22. [24]Jiang, J.; Zhang, Y.; Feng, K.; Wu, X.; Li, W.; Pei, R.; Li, F.; and Zuo, W. 2025. MCˆ 2: Multi-concept Guidance for Customized Multi-concept Generation. In CVPR.arxiv.org/abs/2404.05268
  23. [26]Kirillov, A.; Mintun, E.; Ravi, N.; Mao, H.; Rolland, C.; Gustafson, L.; Xiao, T.; Whitehead, S.; Berg, A. C.; Lo, W.-Y.; et al. 2023. Segment anything. In ICCV.arxiv.org/abs/2304.02643
  24. [27]Lei, S.; Zhang, X.; He, J.; Chen, F.; Du, B.; and Lu, C.-T. 2022. Cross-Domain Few-Shot Semantic Segmentation. In ECCV.DOI
  25. [28]Li, K.; Liu, R.; Cao, X.; Bai, X.; Zhou, F.; Meng, D.; and Wang, Z. 2025a. Segearth-ov: Towards training-free open-vocabulary segmentation for remote sensing images. In CVPR.arxiv.org/abs/2410.01768
  26. [31]Liu, Y.; Jing, C.; Li, H.; Zhu, M.; Chen, H.; Wang, X.; and Shen, C. 2024a. A simple image segmentation framework via in-context examples. NeurIPS.arxiv.org/abs/2410.04842
  27. [32]Liu, Y.; Zhu, M.; Li, H.; Chen, H.; Wang, X.; and Shen, C. 2024b. Matcher: Segment anything with one shot using all-purpose feature matching. In ICLR.arxiv.org/abs/2305.13310
  28. [33]Liu, Y.; Zou, Y.; Li, Y.; and Li, R. 2025b. The devil is in low-level features for cross-domain few-shot segmentation. In CVPR.arxiv.org/abs/2503.21150
  29. [37]Nie, J.; Fu, G.; An, W.; Tan, Y.-P.; Kot, A. C.; and Lu, S. 2026a. Cross-Domain Few-Shot Segmentation via Multi-view Progressive Adaptation. In CVPR.
  30. [38]Nie, J.; Xing, Y.; An, W.; Zhao, Q.; Shao, J.; Tan, Y.-P.; Kot, A. C.; Lu, S.; and Li, X. 2026b. Boosting SAM for Cross-Domain Few-Shot Segmentation via Conditional Point Sparsification. arXiv preprint arXiv:2602.05218.
  31. [39]Nie, J.; Xing, Y.; Zhang, G.; Yan, P.; Xiao, A.; Tan, Y.-P.; Kot, A. C.; and Lu, S. 2024. Cross-Domain Few-Shot Segmentation via Iterative Support-Query Correspondence Mining. In CVPR.
  32. [40]Oquab, M.; Darcet, T.; Moutakanni, T.; Vo, H.; Szafraniec, M.; Khalidov, V.; Fernandez, P.; Haziza, D.; Massa, F.; El-Nouby, A.; et al. 2023. Dinov2: Learning robust visual features without supervision. arXiv preprint arXiv:2304.07193.
  33. [41]Peng, S.-F.; Sun, G.; Li, Y.; Wang, H.; and Xie, G.-S. 2025. SAM-Aware Graph Prompt Reasoning Network for Cross-Domain Few-Shot Segmentation. In AAAI.
  34. [42]Podell, D.; English, Z.; Lacey, K.; Blattmann, A.; Dockhorn, T.; Müller, J.; Penna, J.; and Rombach, R. 2024. Sdxl: Improving latent diffusion models for high-resolution image synthesis. In ICLR.
  35. [43]Radford, A.; Kim, J. W.; Hallacy, C.; Ramesh, A.; Goh, G.; Agarwal, S.; Sastry, G.; Askell, A.; Mishkin, P.; Clark, J.; et al. 2021. Learning transferable visual models from natural language supervision. In ICML.
  36. [44]Raj, A.; Kaza, S.; Poole, B.; Niemeyer, M.; Ruiz, N.; Mildenhall, B.; Zada, S.; Aberman, K.; Rubinstein, M.; Barron, J.; et al. 2023. Dreambooth3d: Subject-driven text-to-3d generation. In ICCV.arxiv.org/abs/2303.13508
  37. [45]Ravi, N.; Gabeur, V.; Hu, Y.-T.; Hu, R.; Ryali, C.; Ma, T.; Khedr, H.; Rädle, R.; Rolland, C.; Gustafson, L.; et al. 2024. Sam 2: Segment anything in images and videos. arXiv preprint arXiv:2408.00714.
  38. [46]Rombach, R.; Blattmann, A.; Lorenz, D.; Esser, P.; and Ommer, B. 2022. High-resolution image synthesis with latent diffusion models. In CVPR.
  39. [47]Ruiz, N.; Li, Y.; Jampani, V.; Pritch, Y.; Rubinstein, M.; and Aberman, K. 2023. Dreambooth: Fine tuning text-to-image diffusion models for subject-driven generation. In CVPR.
  40. [48]Sakurai, K.; Shimizu, R.; and Goto, M. 2025. Vision and language reference prompt into sam for few-shot segmentation. arXiv preprint arXiv:2502.00719.
  41. [50]Sun, Y.; Chen, J.; Zhang, S.; Zhang, X.; Chen, Q.; Zhang, G.; Ding, E.; Wang, J.; and Li, Z. 2024. VRP-SAM: SAM with visual reference prompt. In CVPR.
  42. [51]Tian, P.; Zhou, X.; Yu, H.; and Xie, S. 2025. High Specificity Guided Cross-Domain Few-Shot Segmentation. TMM.
  43. [52]Tong, J.; Zou, Y.; Chen, G.; Li, Y.; and Li, R. 2025. Self-Disentanglement and Re-Composition for Cross-Domain Few-Shot Segmentation. In ICML.
  44. [53]Tong, J.; Zou, Y.; Li, Y.; and Li, R. 2024. Lightweight Frequency Masker for Cross-Domain Few-Shot Semantic Segmentation. In NeurIPS.
  45. [54]Tschandl, P.; Rosendahl, C.; and Kittler, H. 2018. The HAM10000 dataset, a large collection of multi-source dermatoscopic images of common pigmented skin lesions. Scientific Data.
  46. [55]Wang, W.; Duan, L.; Wang, Y.; En, Q.; Fan, J.; and Zhang, Z. 2022. Remember the Difference: Cross-Domain Few-Shot Semantic Segmentation via Meta-Memory Transfer. In CVPR.
  47. [59]Xiao, A.; Xuan, W.; Qi, H.; Xing, Y.; Ren, R.; Zhang, X.; Shao, L.; and Lu, S. 2024. Cat-sam: Conditional tuning for few-shot adaptation of segment anything model. In ECCV.
  48. [61]Yang, J.; Huang, Y.; He, X.; Shen, L.; and Qiu, G. 2024. TAVP: Task-Adaptive Visual Prompt for Cross-domain Few-shot Segmentation. arXiv preprint arXiv:2409.05393.
  49. [62]Zhang, A.; Gao, G.; Jiao, J.; Liu, C.; and Wei, Y. 2024a. Bridge the points: Graph-based few-shot segment anything semantically. In NeurIPS.arxiv.org/abs/2410.06964
  50. [63]Zhang, R.; Jiang, Z.; Guo, Z.; Yan, S.; Pan, J.; Ma, X.; Dong, H.; Gao, P.; and Li, H. 2024b. Personalize segment anything model with one shot. In ICLR.
  51. [64]Zhu, M.; Liu, Y.; Luo, Z.; Jing, C.; Chen, H.; Xu, G.; Wang, X.; and Shen, C. 2024. Unleashing the potential of the diffusion model in few-shot semantic segmentation. In NeurIPS.

Paper details

vlnc:W_nc7x7zbn
v1 · latestHistory (1)

published · Fresh — added to the Hub within the last 30 days

added ·

Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

CC BY 4.0

Original source

  • Computer Science

Not recorded for this paper · View statement →

Looking for related papers…
Contents