Unlocking the Power of SAM 2 for Few-Shot Segmentation

Qianxiong Xu, Lanyun Zhu, Xuanyi Liu, Guosheng Lin, Cheng Long, Ziyue Li, Rui Zhao · OpenReview

Abstract

Few-Shot Segmentation (FSS) aims to learn class-agnostic segmentation on few classes to segment arbitrary classes, but at the risk of overfitting. To address this, some methods use the well-learned knowledge of foundation models (e.g., SAM) to simplify the learning process. Recently, SAM 2 has extended SAM by supporting video segmentation, whose class-agnostic matching ability is useful to FSS. A simple idea is to encode support foreground (FG) features as memory, with which query FG features are matched and fused. Unfortunately, the FG objects in different frames of SAM 2's video data are always the same identity, while those in FSS are different identities, i.e., the matching step is incompatible. Therefore, we design Pseudo Prompt Generator to encode pseudo query memory, matching with query features in a compatible way. However, the memories can never be as accurate as the real ones, i.e., they are likely to contain incomplete query FG, and some unexpected query background (BG) features, leading to wrong segmentation. Hence, we further design Iterative Memory Refinement to fuse more query FG features into the memory, and devise a Support-Calibrated Memory Attention to suppress the unexpected query BG features in memory. Extensive experiments have been conducted on PASCAL-5$^i$ and COCO-20$^i$ to validate the effectiveness of our design, e.g., the 1-shot mIoU can be 4.2% better than the best baseline.

The Identity vs. Category Gap

Few-Shot Segmentation (FSS) is the challenge of segmenting objects from a "novel" class using only one or a few annotated examples (the "support" set). While foundation models like the original SAM are excellent at general segmentation, they often struggle with the specific task of matching a support object to a query object of the same class.

The recently released SAM 2 was designed for video, excelling at "same-object matching"—tracking a specific identity across frames. However, FSS requires "intra-class matching"—finding a different object that belongs to the same category as the support object. A naive application of SAM 2 fails because its internal memory mechanisms expect the exact same identity. This creates an incompatible matching problem: SAM 2’s parameters are tuned for identity, while FSS needs them to generalize across a category.

Comparison between SAM 2's native video tracking and the proposed FSSAM approach for Few-Shot Segmentation.

Proposed Method: FSSAM

To bridge this gap, the authors propose FSSAM (Few-Shot Segment Anything Model), which introduces three key modules to make SAM 2 compatible with the FSS task.

1. Pseudo Prompt Generator (PPG)

Since SAM 2 requires prompts to function, PPG uses a frozen DINOv2 model to generate "pseudo" query masks. It creates two types of priors: a Foreground (FG) prior (high recall, but noisy) and a Discriminative (Disc) prior (high precision, but incomplete). These act as semantic "hints" that trick SAM 2 into treating the query image as if it were a subsequent frame in a video, providing the necessary starting point for matching.

2. Iterative Memory Refinement (IMR)

The pseudo-masks from PPG are inherently imperfect. IMR iteratively fuses features from the "noisy" FG prior into the "clean" Disc prior. By using the support image as a guide, it ensures only relevant category features are added to the query memory, preventing background noise from leaking into the representation. The authors found that refining the memory three times is the "sweet spot" for performance.

3. Support-Calibrated Memory Attention (SCMA)

Even after refinement, the memory might contain residual background features. SCMA "calibrates" the cross-attention scores by using support features to suppress areas in the query memory that do not match the target class. This ensures the final mask decoder focuses exclusively on the correct object boundaries.

The overall architecture of FSSAM, featuring the Pseudo Prompt Generator (PPG), Iterative Memory Refinement (IMR), and Support-Calibrated Memory Attention (SCMA).

Experimental Results

FSSAM was evaluated on standard FSS benchmarks, including PASCAL-5ⁱ and COCO-20ⁱ, as well as LVIS-92ⁱ to test generalization to granular categories. The model achieves state-of-the-art results without adding a massive number of new parameters, primarily by fine-tuning existing SAM 2 components (memory encoder, attention, and mask decoder) while keeping heavy image encoders frozen.

  • PASCAL-5ⁱ: Achieved a 1-shot mIoU of 81.0%, outperforming the previous best foundation-based model (FounFSS) by 4.2%.
  • COCO-20ⁱ: Reached 62.3% mIoU in the 1-shot setting.
  • 5-Shot Performance: In 5-shot scenarios, the mIoU climbed to 85.4% on PASCAL and 69.3% on COCO.

Conclusion and Future Work

FSSAM demonstrates that SAM 2's powerful video tracking capabilities can be effectively repurposed for Few-Shot Segmentation by bridging the identity-category gap. While the system is robust, its success depends on the initial priors generated by PPG. If the foreground and background are visually indistinguishable, the refinement steps may struggle. Future research could explore dedicated error correction modules to handle these difficult edge cases where the target object is initially missed by the pseudo-masking process.

Summary updated

BibTeX
@inproceedings{xu2025unlocking,
  author = {Qianxiong Xu and Lanyun Zhu and Xuanyi Liu and Guosheng Lin and Cheng Long and Ziyue Li and Rui Zhao},
  title = {{Unlocking the Power of SAM 2 for Few-Shot Segmentation}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=TQtUTC3eKv},
}
Figure