Bridge the Points: Graph-based Few-shot Segment Anything Semantically

Anqi Zhang, Guangyu Gao, Jianbo Jiao, Chi Harold Liu, Yunchao Wei

TL;DR

GF-SAM introduces a training-free, hyperparameter-free framework that effectively adapts the Segment Anything Model (SAM) for few-shot semantic segmentation. By modeling the relationships between point prompts and SAM-generated masks as a directed graph, the method achieves state-of-the-art accuracy using only a single round of mask generation, drastically reducing inference time.

What Problem Does This Paper Address?

The Segment Anything Model (SAM) is incredibly powerful at generating precise object masks, but it is class-agnostic and relies heavily on manual prompts (like points or bounding boxes). Adapting SAM to Few-shot Semantic Segmentation (FSS)—where a model must learn to segment a novel class given only a few labeled reference images—remains a challenge.

Existing automated methods attempt to generate prompts for SAM using external feature extractors. However, they suffer from two major flaws:

  1. Granularity Mismatch: They struggle to align fine-grained pixel features (used to select point prompts) with the coarse-grained masks generated by SAM.
  2. Efficiency Bottlenecks: To fix errors, previous approaches repeatedly query SAM in iterative refinement loops or generate excessive mask proposals, leading to prolonged inference times and heavy reliance on hand-tuned hyperparameters.

Methods

The authors propose GF-SAM (Graph-based Few-shot SAM), a streamlined, parameter-free framework that generates masks in a single pass.

Figure 2: Overview of our approach, where the Positive-Negative Alignment module recognizes the correlation between target features and reference features for point selection, the Point-Mask Clustering module efficiently clusters the points based on the coverage of corresponding masks, and Post-Gating filters out the false-positive masks for generating final prediction.

The pipeline consists of three core components:

  1. Positive-Negative Alignment (PNA): Using dense features from an external backbone (DINOv2), the model computes pixel-wise correlations between the target and reference images. Crucially, it leverages the reference image's background as a negative reference to suppress noise and dynamically select a balanced set of target point prompts.
  2. Point-Mask Clustering (PMC): Instead of using complex heuristics to merge masks, GF-SAM constructs a directed graph where vertices represent the selected points and their corresponding SAM masks. An edge is drawn from point $A$ to point $B$ if $A$'s mask covers point $B$. By finding the weakly connected components of this graph, the model automatically clusters points and masks that belong to the same semantic object without needing any hyperparameters.
  3. Post-Gating Strategy: To filter out false positives from the PNA module, two gating mechanisms are applied to the clusters:
  4. Positive Gating: Uses a Mask Growth algorithm to iteratively merge masks that contain more predicted foreground than background.
  5. Overshooting Gating: Eliminates "overshooting" masks (masks that bleed past object boundaries) by evaluating the feature similarity and spatial self-consistency between points and their cluster masks.

Datasets

The authors evaluated their approach across three distinct segmentation tasks using several standard benchmarks:

  • Standard FSS: Pascal-$5^i$, COCO-$20^i$, FSS-1000, and the highly challenging LVIS-$92^i$.
  • One-shot Part Segmentation: PASCAL-Part and PACO-Part (evaluating the ability to segment specific object parts rather than whole objects).
  • Cross-Domain FSS: Deepglobe (satellite imagery), ISIC (skin lesions), and iSAID-$5^i$ (aerial imagery) to test generalization across drastically different visual domains.

Key Insights and Ideas

  • Graph Theory Simplifies Granularity Alignment: Treating mask coverage as a directed graph allows natural topological clustering. Decomposing the graph into weakly connected components completely bypasses the need for traditional clustering algorithms (like k-means++) which require specifying the number of clusters ($k$) beforehand.
  • The Background is an Asset: Most FSS methods focus exclusively on foreground similarity. GF-SAM demonstrates that explicitly modeling background context (negative alignment) is vital for filtering out false-positive prompts in complex scenes.
  • One-and-Done Mask Generation: Iterative refinement loops with foundation models are computationally expensive. This paper proves that a single, well-gated pass through SAM can outperform multi-stage iterative methods if the underlying point-mask relationships are properly modeled.

Key Results

GF-SAM achieves a superior balance between accuracy and computational efficiency compared to prior state-of-the-art generalist models.

Figure 1: Performance comparisons of our approach against previous state-of-the-art methods regarding efficiency and generalized capabilities in Few-shot Semantic Segmentation. Figure 1(a) illustrates our approach’s superior performance in efficiency and effectiveness across various model sizes. Figure 1(b) demonstrates the generalizability of our approach across different domains.
  • Accuracy Leaps: On standard FSS, it achieves a mean Intersection over Union (mIoU) of 58.7% on COCO-$20^i$ (a 6.0% improvement over Matcher) and 35.2% on LVIS-$92^i$.
  • Inference Speedup: On COCO-$20^i$, GF-SAM clocks an inference speed of 1.88 seconds per image, compared to 12.7 seconds for Matcher—nearly a $7\times$ speedup achieved by eliminating redundant SAM queries.
  • Cross-Domain Robustness: Without any fine-tuning, the model outperformed the previous best generalist model on specialized datasets, beating it by 10.1% on ISIC and 13.8% on iSAID-$5^i$.

Limitations and Future Work

The primary limitation stems from a spatial resolution mismatch between the feature extractor (DINOv2) and SAM. When mapping coordinates from the dense feature map back to the original image resolution for SAM prompting, a coordinate bias of up to 28 pixels can occur. This makes the framework less effective at localizing and segmenting very small objects. The authors note that future work will focus specifically on resolving this small-object localization bottleneck.

Summary updated

BibTeX
@inproceedings{zhang2024bridge,
  author = {Anqi Zhang and Guangyu Gao and Jianbo Jiao and Chi Harold Liu and Yunchao Wei},
  title = {{Bridge the Points: Graph-based Few-shot Segment Anything Semantically}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=jYypS5VIPj},
}
Figure