Personalize Segment Anything Model with One Shot

Renrui Zhang, Zhengkai Jiang, Ziyu Guo, Shilin Yan, Junting Pan, Hao Dong, Yu Qiao, Peng Gao, Hongsheng Li

TL;DR

PerSAM (Personalized Segment Anything Model) enables the world-renowned Segment Anything Model (SAM) to recognize and segment specific, private visual concepts—like your own pet or a favorite backpack—using just a single reference image. By introducing a training-free approach and a lightning-fast 10-second fine-tuning variant, the authors transform a general-purpose "segment everything" tool into a specialized personal assistant.

The Challenge of One-Shot Personalization

Meta’s Segment Anything Model (SAM) revolutionized computer vision by providing a powerful "foundation model" for segmentation. It excels at isolating objects when prompted with a point or a box. However, SAM is a generalist; it doesn't inherently "know" who your specific dog is. If you want to segment your dog across 100 different vacation photos, you would traditionally have to manually prompt SAM for every single image.

The core challenge is one-shot personalization: how do we teach a massive, frozen model to identify a specific instance of an object using only one example, without requiring a massive GPU cluster or hours of retraining? Furthermore, SAM often suffers from "scale ambiguity"—it might not know if you want to segment just the lid of a teapot (the subpart) or the entire teapot (the whole).

PerSAM Pipeline

Proposed Methods: PerSAM and PerSAM-F

To address these challenges, the authors propose two distinct solutions: a training-free approach (PerSAM) and an efficient fine-tuning variant (PerSAM-F).

1. PerSAM (Training-Free)

This version works out of the box by guiding SAM’s internal logic without altering its weights:

  • Location Confidence Map: It compares the visual features of your reference object with the new image to create a "heat map." It then selects the highest-confidence point as a positive prompt and the lowest as a negative prompt.
  • Target-Guided Attention: It modifies SAM’s internal attention mechanism so the model focuses primarily on the regions identified in the heat map.
  • Target-Semantic Prompting: It injects the actual visual features (the "vibe") of the reference object directly into SAM’s prompt tokens, providing the model with high-level context about what it is looking for.

2. PerSAM-F (Fine-Tuning)

To solve the scale ambiguity problem, the authors developed a "micro" fine-tuning approach. SAM naturally produces three different masks for any given prompt (e.g., whole, part, and subpart). PerSAM-F introduces just two learnable parameters that represent the weights for these three masks. By training only these two numbers on the single reference image, the model learns which scale the user cares about. Remarkably, this process takes less than 10 seconds on a single GPU.

Datasets and Evaluation

  • PerSeg (New Benchmark): The authors introduced this dataset specifically for personalized segmentation. It contains 40 different objects (animals, daily items, buildings) with 5–7 images each, captured in various poses and environments.
  • Evaluation Benchmarks: The model was rigorously tested on DAVIS 2017 (video object segmentation) and several one-shot semantic/part segmentation datasets, including FSS-1000, LVIS-92i, and PASCAL-Part.

Key Insights and Results

  • The "Aha" Moment on Scale: The most elegant realization in the paper is that you don't need to retrain SAM's massive backbone to make it personal. SAM already "sees" the object; it just doesn't know which part you want. Learning the weights for the three output scales is a mathematically tiny problem that yields massive performance gains.
  • Synergy with DreamBooth: PerSAM can act as an effective "cleaner" for DreamBooth (a popular tool for personalizing text-to-image models). By using PerSAM to mask out the background of training images, it prevents DreamBooth from learning the background as part of the object, leading to much higher fidelity in generated images.
  • Superior Accuracy and Efficiency: On the PerSeg dataset, PerSAM-F achieved a 95.3 mIoU (Mean Intersection over Union), outperforming other in-context learners like SegGPT. In video tracking (DAVIS 2017), the training-free PerSAM outperformed the previous state-of-the-art by a staggering 32.3% in J&F score. All of this is achieved with a 10-second training time, making it highly practical for consumer applications.

Limitations and Future Directions

While powerful, the authors acknowledge a few hurdles:

  • Fine-Grained Sensitivity: The model can struggle with very similar-looking objects (e.g., distinguishing between different human faces), as SAM’s features are somewhat class-agnostic.
  • Extreme Occlusion: If the distinctive part of an object is hidden in the test image, the location prior may fail.
  • Discontinuous Objects: SAM occasionally struggles with objects that are split into multiple pieces within the frame.

Looking forward, the authors suggest that as even stronger foundation models (like DINOv2) emerge, they can be seamlessly swapped into the PerSAM framework to provide even more discriminative power for complex scenes.

Summary updated

BibTeX
@inproceedings{zhang2024personalize,
  author = {Renrui Zhang and Zhengkai Jiang and Ziyu Guo and Shilin Yan and Junting Pan and Hao Dong and Yu Qiao and Peng Gao and Hongsheng Li},
  title = {{Personalize Segment Anything Model with One Shot}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=6Gzkhoc6YS},
}
Figure