WorksComputer Science
From Visual Matching to Textual Conditioning: Cross-Domain Few-Shot Segmentation via Reference Inversion
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.

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 () and a lower standard deviation of per-image IoU () 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.
Related Work
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 -shot setting, a reference set is provided for category , where and denote the -th reference image and its ground-truth mask, respectively. Given a target image of the same category, the goal is to predict its segmentation mask using the available reference set .
Reference-Target Visual Matching. Previous CD-FSS methods generally condition each target prediction directly on the references: , where 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 , requiring reference-target visual matching to be performed for every . Therefore, such visual similarity is sensitive to appearance variations (refer to Figure 1).
Reference Inversion. In this paper, we reformulate the role of references in CD-FSS. Instead of performing visual matching between and each , we invert the references into a reusable textual condition that can be shared across target images. Let denote the pre-trained SAM3 with frozen parameters . Given , we obtain while keeping frozen. After inversion, is discarded, and target prediction is performed as . This formulation decouples predictions from target inference, allowing to be reused across all target images without further access to . 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 before the text encoder and the reference concept tokens after it. Layer-adaptive Textual Conditioning combines the encoded reference word tokens and with layer-wise fusion coefficients to construct the bi-level reference tokens for conditioning different decoder layers. Presence-aware Confidence Supervision further improves prediction reliability by supervising mask quality, query classification, and target presence. Once inverted, is reused across target images without further access to the annotated references.

Figure 2. Overview of our proposed RI-SAM3 framework. Bi-level Reference Inversion (BRI) learns reference word tokens and reference concept tokens from annotated references, collectively termed inverted reference tokens. Layer-adaptive Textual Conditioning (LTC) combines them with layer-specific fusion coefficients to produce the bi-level reference tokens for conditioning frozen SAM3. Presence-aware Confidence Supervision (PCS) jointly supervises query-level classification and global presence scores. Once learned, 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 denote the frozen text encoder of SAM3. We introduce a learnable reference word embedding at its input and optimize it using the annotated references. The frozen text encoder maps to the reference word tokens:
Because 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 directly after the text encoder. Without being constrained by the text encoding process, can more flexibly represent the target-category concept specified by the references. They are independently optimized using the annotated references:
where represents supervision introduced below. The resulting reference word tokens and reference concept tokens are collectively referred to as the inverted reference tokens.
Layer-adaptive Textual Conditioning
SAM3 progressively refines its object-query tokens through 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 -th layer are constructed as:
where is the learnable fusion coefficient of the -th decoder layer. Omitting residual connections, normalization, and feed-forward layers for clarity, the object-query tokens are updated as:
where 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: using the annotated references:
where collects the layer-specific bi-level reference tokens. Once optimized, remains fixed and is shared across all target images of category .
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 and denote the mask and classification logits of the -th object query, respectively, and let denote the global presence logit. We first apply standard BCE and Dice losses to the reference prediction :
For each query, we use its soft mask IoU as the quality target:
where 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:
where 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:
Overall, Reference Inversion is optimized in two stages. We first learn and 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, 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 . 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.
| Method | Venue | ISIC 1-shot | ISIC 5-shot | Chest X-Ray 1-shot | Chest X-Ray 5-shot | DeepGlobe 1-shot | DeepGlobe 5-shot | SUIM 1-shot | SUIM 5-shot |
| Conventional ResNet-/ViT-based Methods | |||||||||
| ISA | ICCV 2025 | 37.2 | 56.1 | 83.4 | 86.3 | 44.3 | 52.7 | 44.1 | – |
| DR-Adapter | CVPR 2024 | 40.8 | 48.9 | 82.4 | 82.3 | 41.3 | 50.1 | – | – |
| PATNet | ECCV 2022 | 41.2 | 53.6 | 66.6 | 70.2 | 37.9 | 43.0 | 32.1 | 40.2 |
| APM | NeurIPS 2024 | 41.7 | 51.2 | 78.3 | 82.8 | 40.9 | 44.9 | – | – |
| ABCDFSS | CVPR 2024 | 45.7 | 53.3 | 79.8 | 81.4 | 42.6 | 49.0 | 35.1 | 41.3 |
| SDRC | ICML 2025 | 46.6 | 55.0 | 82.9 | 84.8 | 43.2 | 46.8 | – | – |
| DFN | ICML 2025 Spotlight | 50.4 | 58.5 | 83.2 | 87.1 | 39.5 | 47.7 | – | – |
| LoEC | CVPR 2025 | 52.9 | 62.4 | 83.9 | 84.1 | 42.1 | 51.5 | – | – |
| IFA | CVPR 2024 | 66.3 | 69.8 | 74.0 | 74.6 | 50.6 | 58.8 | – | – |
| DATO | CVPR 2025 | 68.8 | 70.3 | 79.6 | 81.1 | 51.1 | 59.3 | – | – |
| Vision Foundation Model-based Methods | |||||||||
| PerSAM | ICLR 2024 | 23.9 | – | – | – | 31.4 | – | – | – |
| Matcher | ICLR 2024 | 38.6 | 35.0 | 66.8 | 66.3 | 48.1 | 50.9 | 37.9 | 41.4 |
| APSeg | CVPR 2024 | 45.4 | 54.0 | 84.1 | 84.5 | 35.9 | 40.0 | – | – |
| TAVP | arXiv 2024 | 54.9 | – | – | – | 46.1 | – | – | – |
| CPS | arXiv 2026 | 51.3 | 56.6 | 70.0 | 70.2 | 46.0 | 49.8 | 42.8 | 48.8 |
| GF-SAM | NeurIPS 2024 Spotlight | 48.7 | 55.2 | 47.6 | 47.4 | 49.5 | 57.7 | 38.3 | 42.9 |
| PerSAM-F* | ICLR 2024 | 20.5 | – | 38.7 | – | 46.5 | – | 10.3 | – |
| VLP-SAM* | arXiv 2025 | 34.8 | 45.9 | 54.7 | 59.1 | 48.1 | 52.4 | 16.9 | 26.9 |
| INSID3 | CVPR 2026 Oral | 54.4 | 63.9 | 78.8 | 80.1 | – | – | 54.9 | 61.7 |
| RI-SAM3* | – | 64.1 | 71.4 | 90.5 | 91.0 | 51.8 | 55.8 | 63.2 | 78.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.

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 design | ISIC | Chest X-Ray | DeepGlobe | SUIM |
| SAM3 + category-name | 10.2 | 24.4 | 21.5 | 16.1 |
| SAM3 + BRI | 54.9 | 89.3 | 23.8 | 54.4 |
| + LTC | 59.8 | 89.5 | 43.9 | 58.8 |
| + PCS | 64.1 | 90.5 | 51.8 | 63.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.
| Method | ISIC | Chest X-Ray | DeepGlobe | SUIM |
| PerSAM-F | ||||
| VLP-SAM | ||||
| RI-SAM3 |
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 FLOPs, less than the and 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 | |||||
| Method | Preparation | Inference | Total | ||
| PATNet | 538 | 5 | 543 | ||
| IFA | 541 | 5 | 545 | ||
| SAM-based Methods | |||||
| Method | Prep. | Inf. | Total | Model size (M) | FLOPs (T) |
| Matcher | – | 41 | 41 | 945 | 8.6 |
| GF-SAM | – | 8 | 8 | 945 | 8.4 |
| RI-SAM3 | 2 | 2 | 4 | 840 | 3.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.
| Method | In-Domain FSS | One-Shot Part Seg. | |||
| Pasc.-5i | COCO-20i | FSS. | PASC.-Part | PACO-Part | |
| PerSAM | 43.1 | 23.0 | 71.2 | 32.5 | 22.5 |
| PerSAM-F | 48.5 | 23.5 | 75.6 | 32.9 | 22.7 |
| Matcher | 68.1 | 52.7 | 87.0 | 42.9 | 34.7 |
| VRP-SAM | 71.9 | 53.9 | – | – | – |
| GF-SAM | 72.1 | 58.7 | 88.0 | 44.5 | 36.3 |
| CPS | – | 49.2 | 81.7 | – | – |
| INSID3 | – | 57.6 | – | – | – |
| RI-SAM3 | 80.4 | 70.9 | 91.5 | 57.6 | 45.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]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]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]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]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]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]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]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]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]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]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]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]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]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]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
- [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
- [17]Hariharan, B.; Arbeláez, P.; Girshick, R.; and Malik, J. 2015. Hypercolumns for object segmentation and fine-grained localization. In CVPR.
- [19]Herzog, J. 2024. Adapt Before Comparison: A New Perspective on Cross-Domain Few-Shot Segmentation. In CVPR.arxiv.org/abs/2402.17614
- [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
- [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
- [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
- [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
- [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
- [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
- [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
- [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
- [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
- [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
- [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
- [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.
- [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.
- [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.
- [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.
- [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.
- [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.
- [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.
- [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
- [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.
- [46]Rombach, R.; Blattmann, A.; Lorenz, D.; Esser, P.; and Ommer, B. 2022. High-resolution image synthesis with latent diffusion models. In CVPR.
- [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.
- [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.
- [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.
- [51]Tian, P.; Zhou, X.; Yu, H.; and Xie, S. 2025. High Specificity Guided Cross-Domain Few-Shot Segmentation. TMM.
- [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.
- [53]Tong, J.; Zou, Y.; Li, Y.; and Li, R. 2024. Lightweight Frequency Masker for Cross-Domain Few-Shot Semantic Segmentation. In NeurIPS.
- [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.
- [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.
- [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.
- [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.
- [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
- [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.
- [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.