Adapting the Segment Anything Model During Usage in Novel Situations

Robin Schön, Julian Lorenz, Katja Ludwig, Rainer Lienhart

Abstract

The Segment Anything Model (SAM) has established itself as a powerful foundation model for general-purpose image segmentation. However, its performance often degrades when applied to specialized domains such as medical imaging or underwater exploration. This paper introduces a test-time adaptation framework that fine-tunes SAM’s lightweight mask decoder in real-time using sparse user interactions. By leveraging user clicks as pseudo-labels and employing iterative morphological erosion to refine training signals, the proposed method reduces failure rates by up to 48% without requiring pre-existing labeled datasets.

Introduction

While SAM was trained on over 1.1 billion masks, it faces a significant "generalization gap" in niche domains. In fields like forestry, camouflaged object detection, or medical endoscopy, SAM frequently fails to produce accurate boundaries even with multiple user prompts. Traditional fine-tuning is often impractical due to the high computational cost and the lack of large-scale labeled data in these specialized areas.

The authors propose a solution to this "catch-22" by adapting the model during the annotation process itself. By treating user interactions not just as prompts but as training signals, the model can bridge the domain gap on-the-fly.

Methodology: Test-Time Adaptation

The core of the proposed framework is the adaptation of SAM's Mask Decoder. Unlike the massive image encoder, the decoder contains only about 4 million parameters, allowing for rapid optimization between user clicks.

Overview of the proposed adaptation framework within the Segment Anything Model (SAM).

Key Adaptation Strategies

  • Click Adaptation (CA): User clicks are treated as ground-truth labels for specific pixels. The model performs a quick optimization step to "overfit" to the current image, improving immediate segmentation accuracy.
  • Mask-Based Adaptation: Once a user confirms a mask, it serves as a pseudo-label to update the model for subsequent images in a sequence.
  • Iterative Morphological Erosion: To ensure high-quality training signals, the system "erodes" the pseudo-label masks. By focusing on the interior pixels and ignoring uncertain boundaries, the model avoids learning from its own potential errors.
  • Multiple Decoders: The system can maintain separate decoder weights for different object classes to prevent interference during multi-class annotation tasks.

Experiments and Results

The framework was evaluated across diverse "out-of-distribution" datasets, including aerial imagery (Rooftop), underwater debris (TrashCan), camouflaged animals (CAMO), and various medical datasets (KvasirSeg, CVCClinicDB).

Qualitative examples across various datasets showing ground truth (GT), user clicks, and the eroded masks used for adaptation.

Performance Gains

The primary metric used was the Failure Rate (FR)—the percentage of images where the model failed to achieve a target IoU within a fixed number of clicks.

  • Medical Imaging: On the KvasirSeg dataset, the failure rate was nearly halved, dropping from 2.7% to 1.4%.
  • Specialized Objects: In the challenging TrashCan dataset, the failure rate decreased from 57.42% to 40.49%.
  • Efficiency: The adaptation step takes approximately 43ms on a V100 GPU, ensuring that the user experience remains interactive and real-time.

Discussion and Conclusion

A notable finding is that larger models like HQ-SAM do not necessarily perform better in niche domains; in some cases, they performed worse than the original SAM. This highlights the importance of domain-specific adaptation over sheer model scale.

The current method relies on sequence consistency; its benefits are most pronounced when annotating similar images (e.g., frames from a video or a series of similar scans). Future work may explore adapting small portions of the image encoder or developing more sophisticated methods to mitigate catastrophic forgetting when switching between highly dissimilar object types. Overall, this real-time adaptation strategy provides a robust, data-efficient path for deploying foundation models in specialized scientific and industrial fields.

Summary updated

BibTeX
@inproceedings{schon2024adapting,
  author = {Robin Schön and Julian Lorenz and Katja Ludwig and Rainer Lienhart},
  title = {{Adapting the Segment Anything Model During Usage in Novel Situations}},
  booktitle = {Workshops @ CVPR},
  year = {2024},
  doi = {10.1109/cvprw63382.2024.00365},
}
Figure