NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

AutoSAM: Adapting SAM to Medical Images by Overloading the Prompt Encoder

Tal Shaharabany, Aviad Dahan, Raja Giryes, Lior Wolf · DOI

Introduction

The Segment Anything Model (SAM) represents a paradigm shift in computer vision, demonstrating unprecedented zero-shot segmentation capabilities across a vast array of natural image domains. However, its application in the clinical sphere has been hampered by two primary obstacles: the significant domain gap between natural and medical imagery, and the reliance on manual prompting (points or bounding boxes). While medical images—such as ultrasounds, MRIs, and histopathology slides—are fundamentally different from the natural images in SAM's training set, the model's underlying feature representation remains highly potent.

AutoSAM addresses these challenges by introducing a novel "overloading" mechanism. Instead of computationally expensive fine-tuning of the entire SAM architecture, AutoSAM utilizes a lightweight, image-driven prompt generator to automate the segmentation process, effectively transforming SAM into a fully autonomous medical imaging tool.

The Problem: Domain Gaps and Prompting Burdens

SAM's performance often plummets when faced with "Out-Of-Distribution" (OOD) medical data. Furthermore, the requirement for human-in-the-loop prompting is a significant bottleneck in high-volume clinical workflows. While some researchers have attempted to fine-tune SAM’s massive internal weights (approximately 637M parameters), this approach is not only resource-intensive but also risks "catastrophic forgetting," where the model loses the generalized features that made it powerful initially. There is a clear need for a method that leverages SAM’s pre-trained expertise while removing the need for manual intervention.

Methodology: Overloading the Prompt Encoder

The core innovation of AutoSAM is the concept of prompt overloading, a term borrowed from object-oriented programming. In the original SAM architecture, the prompt encoder is designed to process points, boxes, or masks. AutoSAM "overloads" this input by training a custom network, denoted as $g$, which accepts the raw input image and transforms it into a "surrogate prompt" that the frozen SAM model can interpret.

Technical Architecture

  1. Frozen Foundation: To preserve the integrity of the original model, the heavy Vision Transformer (ViT) image encoder and the mask decoder within SAM remain completely frozen. No weights are updated in these layers.
  2. The Prompt Generator ($g$): This trainable component utilizes a Harmonic Dense Net (HarDNet-85) backbone. It is significantly more efficient than the full SAM model, containing roughly 41.5M parameters.
  3. Gradient Flow and Optimization: During the training phase, the error (loss) is calculated at the final mask output. Gradients are then backpropagated through the frozen SAM layers to update only the weights of the prompt generator $g$. The optimization uses a combination of Binary Cross-Entropy (BCE) and Dice loss to ensure both pixel-level precision and global shape accuracy.
  4. Surrogate Decoder ($h$): To validate the information contained within the learned surrogate prompts, the researchers implemented a tiny deconvolutional network ($h$). This allows for the visualization of the prompt as a mask, confirming that the generator is indeed learning relevant anatomical features.

Experimental Results

AutoSAM was rigorously evaluated across several diverse medical imaging benchmarks, including MoNuSeg (cell nuclei), GlaS (gland segmentation), and multiple polyp segmentation datasets (Kvasir-SEG, ClinicDB, ColonDB, ETIS, and SUN-SEG).

Performance Highlights

  • MoNuSeg: AutoSAM achieved a Dice score of 82.43, surpassing the previous state-of-the-art (MedAdapter-SAM) which scored 80.34. Notably, AutoSAM significantly outperformed standard SAM even when the latter was provided with manual ground-truth point prompts (82.43 vs. 29.65 Dice), suggesting that the learned surrogate prompts are far more descriptive than simple human clicks.
  • GlaS: The model reached a Dice score of 92.82, a substantial improvement over the standard U-Net baseline of 86.05.
  • Video Segmentation: On the SUN-SEG video dataset, AutoSAM achieved state-of-the-art results across nearly every metric. This is particularly impressive given that AutoSAM is an image-based model that does not explicitly account for temporal data between frames.

Discussion and Insights

The success of AutoSAM yields a vital insight: SAM is a "Latent Expert." The model already possesses the necessary features to segment medical structures; it simply requires the correct guidance to identify them. By providing this guidance through a custom, automated prompt, AutoSAM bridges the gap between interactive and autonomous AI.

Furthermore, the efficiency of this approach demonstrates that training a small "adapter" (the prompt generator) is often superior to brute-force fine-tuning of large-scale models. This modularity allows for faster training and easier deployment in resource-constrained medical environments.

Future Directions

While AutoSAM currently requires training a specific prompt generator for different datasets, future research aims to develop a "Universal-AutoSAM." Such a model would utilize a single prompt generator capable of handling multiple medical modalities—such as switching between MRI, CT, and histology—without the need for task-specific retraining. Additionally, exploring the generalization of these surrogate prompts to entirely unseen medical tasks remains a priority for the continued evolution of autonomous clinical AI.

Summary updated

BibTeX
@inproceedings{shaharabany2023autosam,
  author = {Tal Shaharabany and Aviad Dahan and Raja Giryes and Lior Wolf},
  title = {{AutoSAM: Adapting SAM to Medical Images by Overloading the Prompt Encoder}},
  booktitle = {BMVC},
  year = {2023},
}
Figure