Personalize Segment Anything Model with One Shot

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

Abstract

The Segment Anything Model (SAM) is a powerful foundation model for computer vision, capable of segmenting any object given a prompt. However, it lacks the inherent ability to recognize and track specific object instances across different contexts without repetitive manual intervention. We introduce PerSAM, a personalized segmentation framework that enables SAM to identify a target object—such as a specific pet or toy—using only a single reference image and mask. By employing a training-free approach and an efficient 10-second fine-tuning method (PerSAM-F), we transform SAM into a personalized assistant. Our approach achieves superior accuracy on the PerSeg dataset and demonstrates significant utility in enhancing personalized text-to-image generation.

Introduction

Foundation models like SAM have set new benchmarks in zero-shot segmentation. Despite their versatility, they remain "generalists" that do not retain information about specific visual identities. For instance, segmenting a particular dog across a photo album currently requires manual prompts for every image. This limitation hinders the practical application of SAM in personalized workflows.

The PerSAM pipeline: (1) User provides one image and mask, (2) One-shot learning via training-free or fine-tuning methods, (3) Personalized segmentation in various scenes.

PerSAM addresses this by "personalizing" SAM. Given a single reference image and its corresponding mask, PerSAM can automatically segment the same object in new images or video frames, regardless of changes in pose, lighting, or scale.

Methodology

The researchers propose two distinct strategies for personalization: a training-free version (PerSAM) and a lightweight fine-tuning version (PerSAM-F).

1. PerSAM: Training-Free Personalization

PerSAM leverages the frozen features of the original SAM model to locate the target object through three key mechanisms:

  • Positive-Negative Location Prior: By comparing the features of the reference object with the target image, the model generates a confidence map. It automatically selects the highest-confidence point as a positive prompt and the lowest as a negative prompt for SAM's decoder.
  • Target-Guided Attention: The internal cross-attention layers of SAM are modified to focus specifically on regions highlighted by the confidence map, preventing the model from being distracted by background elements.
  • Target-Semantic Prompting: Visual features of the reference object are injected directly into the decoder, providing the model with a "semantic anchor" of the object's identity.

2. PerSAM-F: Rapid Fine-Tuning

To address scale ambiguity—where SAM might segment a part of an object instead of the whole—PerSAM-F introduces a minimal fine-tuning step. By freezing the entire model except for two learnable parameters that weight SAM’s multi-scale mask outputs, the model learns to select the correct hierarchical level. This process is exceptionally efficient, requiring only 10 seconds on a single GPU.

Synergy with Generative AI

PerSAM's utility extends beyond segmentation. It can be integrated with personalized text-to-image models like DreamBooth. By providing clean, automated masks of the target object during the DreamBooth training phase, PerSAM helps the generative model focus exclusively on the object's identity, leading to higher-quality synthesis with fewer background artifacts.

Comparison of PerSAM and PerSAM-F, and the application of PerSAM in assisting DreamBooth for cleaner personalized image generation.

Experimental Results

The authors evaluated PerSAM on several benchmarks, including a newly introduced dataset, PerSeg, which contains 40 diverse objects with multiple reference images.

  • Accuracy: PerSAM-F achieved a mean Intersection over Union (mIoU) of 95.3 on PerSeg, outperforming other in-context learners like SegGPT (94.3) and Painter (56.4).
  • Efficiency: The 2-parameter fine-tuning is significantly faster and more resource-efficient than standard methods like LoRA.
  • Video Segmentation: On the DAVIS 2017 benchmark, PerSAM-F reached a 76.1 J&F score, demonstrating robust performance in dynamic video environments without being explicitly trained on video data.

Conclusion

PerSAM effectively bridges the gap between general-purpose foundation models and personalized AI applications. By enabling one-shot personalization with minimal to no training overhead, it expands the utility of SAM for individual users and complex downstream tasks like video editing and personalized content creation. Future work may explore extending this personalization logic to other modalities and foundation models.

Summary updated

BibTeX
@inproceedings{zhang2024personalize,
  author = {Renrui Zhang and Zhengkai Jiang and Ziyu Guo and Shilin Yan and Junting Pan and Hao Dong 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