Abstract
The Segment Anything Model (SAM) has garnered significant attention for its versatile segmentation abilities and intuitive prompt-based interface. However, its application in medical imaging presents challenges, requiring either substantial training costs and extensive medical datasets for full model fine-tuning or high-quality prompts for optimal performance. This paper introduces H-SAM: a prompt-free adaptation of SAM tailored for efficient fine-tuning of medical images via a two-stage hierarchical decoding procedure. In the initial stage, H-SAM employs SAM's original decoder to generate a prior probabilistic mask, guiding a more intricate decoding process in the second stage. Specifically, we propose two key designs: 1) A class-balanced, mask-guided self-attention mechanism addressing the unbalanced label distribution, enhancing image embedding; 2) A learnable mask cross-attention mechanism spatially modulating the interplay among different image regions based on the prior mask. Moreover, the inclusion of a hierarchical pixel decoder in H-SAM enhances its proficiency in capturing fine-grained and localized details. This approach enables SAM to effectively integrate learned medical priors, facilitating enhanced adaptation for medical image segmentation with limited samples. Our H-SAM demonstrates a 4.78% improvement in average Dice compared to existing prompt-free SAM variants for multi-organ segmentation using only 10% of 2D slices. Notably, without using any unlabeled data, H-SAM even outperforms state-of-the-art semisupervised models relying on extensive unlabeled training data across various medical datasets.
Introduction
The Segment Anything Model (SAM) revolutionized computer vision with its ability to segment almost anything given a simple prompt. However, SAM has a "medical blind spot." Because it was trained primarily on natural images, its performance drops significantly when faced with the unique textures and low contrast of CT or MRI scans. Adapting SAM to medicine usually faces two hurdles: the "Prompt Tax," where manual prompting is time-consuming for clinicians, and "Data Scarcity," where small medical datasets lead to overfitting during full fine-tuning. H-SAM aims to bridge this gap by making SAM work autonomously and efficiently on medical images through a prompt-free, hierarchical approach.
Methods: Hierarchical Decoding
The core innovation of H-SAM is its two-stage hierarchical decoding process. Instead of a single-pass prediction, the model first generates a "prior probabilistic mask"—a rough spatial guess—using SAM’s original lightweight decoder. This prior then guides a more sophisticated second stage.
Two novel modules are introduced in the refinement stage:
- Class-Balanced Mask-Guided Self-Attention (CMAttn): This addresses the "long-tail" distribution common in medical images (e.g., large liver vs. tiny gallbladder) by using the prior mask and Gaussian noise to ensure the model attends to smaller, rarer categories.
- Learnable Mask Cross-Attention: This module uses the Stage 1 mask to focus the model's attention on relevant anatomical regions, effectively filtering out background noise.
To preserve fine-grained spatial details, H-SAM includes a Hierarchical Pixel Decoder with skip connections, similar to the U-Net architecture. Efficiency is maintained by freezing the massive SAM image encoder and only training LoRA (Low-Rank Adaptation) layers.
Experimental Results
H-SAM was evaluated on three diverse medical benchmarks: Synapse Multi-Organ CT, the Left Atrial (LA) heart MRI dataset, and the PROMISE12 prostate MRI dataset.
Performance in Data-Scarce Scenarios
On the Synapse dataset using only 10% of the available data, H-SAM achieved an 80.35% Mean Dice score, representing a 4.78% improvement over other prompt-free SAM variants. Remarkably, on the PROMISE12 and LA datasets, H-SAM—using only labeled data—outperformed state-of-the-art semi-supervised models that had access to extensive additional unlabeled scans.
Qualitative Insights
Visual results demonstrate that H-SAM is significantly better at distinguishing between adjacent organs with similar intensities, such as the stomach and the liver, which often confuse standard SAM adaptations. By leveraging the spatial prior from the first stage, the model avoids common missegmentation errors in complex abdominal regions.
Conclusion and Future Work
H-SAM demonstrates that a hierarchical approach can effectively adapt large-scale vision models like SAM to specialized domains with limited data. By generating and then refining a spatial prior, H-SAM achieves state-of-the-art performance without requiring manual prompts. Future research will focus on extending this framework to native 3D volumes to improve spatial consistency across slices and further optimizing the computational efficiency of the two-stage decoder.
Summary updated