Learning few-shot semantic segmentation with error-filtered segment anything model

Chen-Bin Feng, Qi Lai, Kangdao Liu, Houcheng Su, Hao Chen, Kaixi Luo, Chi-Man Vong

TL;DR

FSS-SAM is a training-free post-processing framework that uses the Segment Anything Model (SAM) to sharpen the blurry contours typical of few-shot semantic segmentation (FSS). By introducing a simple yet effective "safety valve" called the Prediction Result Selection (PRS) algorithm, the authors consistently improve the accuracy of state-of-the-art FSS models across standard benchmarks.

What Problem Does This Paper Address?

Few-shot semantic segmentation (FSS) aims to segment novel object classes using only a handful of annotated examples. While FSS models are great at identifying what an object is, they often struggle with where its exact boundaries are. Because these models are trained on limited data, they fail to capture fine-grained edge features, resulting in "coarse" masks with fuzzy or inaccurate contours.

This lack of precision is a major hurdle for downstream applications like medical image analysis or high-quality image editing (inpainting), where a few stray pixels can ruin the result. The authors set out to bridge the gap between the general localization ability of FSS models and the high-precision segmentation power of large foundation models.

Methods

The authors propose FSS-SAM, a plug-and-play framework that requires no additional training. The process follows a four-step pipeline:

  1. Base Prediction: An existing FSS model (like BAM or HSNet) generates a coarse initial mask ($M_{FSS}$).
  2. Prompt Generation: This coarse mask is used to automatically generate visual prompts for SAM. Specifically, the authors calculate the centroid point of the mask and its surrounding bounding box (see Figure 4).
  3. SAM Refinement: These prompts, along with the original query image, are fed into a frozen SAM. SAM uses its massive zero-shot knowledge to produce a refined, high-precision mask ($M_{SAM}$).
  4. PRS Algorithm: To prevent SAM from accidentally segmenting the wrong object in complex scenes, the authors introduce the Prediction Result Selection (PRS) algorithm. It calculates the Intersection over Union (IoU) between the original FSS mask and the new SAM mask. If the IoU is above a threshold (empirically set to 0.75), the refined SAM mask is kept. If not, the system reverts to the original FSS mask to avoid a "wrong prediction" (see Figure 3 and Figure 5).
The FSS-SAM framework including the PRS selection logic.

Datasets

The method was evaluated on two standard FSS benchmarks:

  • PASCAL-5i: A dataset containing 20 classes, split into four folds for cross-validation.
  • COCO-20i: A more challenging dataset with 80 classes, also split into four folds. For both, the authors followed the standard protocol of sampling 1,000 episodes for testing.

Key Insights and Ideas

  • Training-Free Synergy: The core "aha" moment is that you don't need to fine-tune a giant model like SAM for FSS. Instead, you can treat SAM as a high-resolution "lens" that sharpens the rough guesses of smaller, specialized models.
  • The PRS Safety Valve: Directly using SAM can sometimes lead to worse results if the prompts are ambiguous or the scene is crowded. The PRS algorithm acts as a crucial filter, ensuring that the refinement only happens when SAM's output is spatially consistent with the base model's intent.
  • Prompt Robustness: The authors found that while they used box prompts for their main experiments, SAM is remarkably robust; using points, boxes, or a mix of both yielded similar performance gains (see Figure 6).
Comparison of different prompt types (point, box, mix).

Key Results

FSS-SAM consistently boosted the performance of base models across different backbones (VGG16 and ResNet50) and settings (1-shot and 5-shot).

  • Quantitative Gains: On PASCAL-5i using a ResNet50 backbone, the base BAM model achieved a mean IoU (mIoU) of 67.8%. Adding FSS-SAM boosted this to 68.5%. The improvement in Foreground-Background mIoU (FB-mIoU) was even more significant, jumping from 77.3% to 80.2% (see Figure 2).
  • Qualitative Improvements: As shown in Figure 1, the refined masks have much cleaner edges. This precision is vital for tasks like image inpainting (IP); where the base FSS mask might leave artifacts, the FSS-SAM mask allows for a seamless edit.
Quantitative comparison showing the boost provided by FSS-SAM and the importance of the PRS algorithm.

Limitations and Future Work

The authors acknowledge that FSS-SAM's success depends heavily on the base FSS model. If the base model fails to locate the object at all (a "wrong location" error), the prompts generated for SAM will be incorrect, and the PRS algorithm will simply return the original (wrong) mask.

Future work could explore more sophisticated ways to handle multi-object scenes or investigate if SAM's internal features could be used to improve the base FSS model's localization during the initial prediction phase, rather than just as a post-processor.

Summary updated

BibTeX
@article{feng2025learning,
  author = {Chen-Bin Feng and Qi Lai and Kangdao Liu and Houcheng Su and Hao Chen and Kaixi Luo and Chi-Man Vong},
  title = {{Learning few-shot semantic segmentation with error-filtered segment anything model}},
  journal = {The Visual Computer},
  year = {2025},
  doi = {10.1007/s00371-025-03809-9},
}
Figure