Unleashing the Potential of SAM for Medical Adaptation via Hierarchical Decoding

Zhiheng Cheng, Qingyue Wei, Hongru Zhu, Yan Wang, Liangqiong Qu, Wei Shao, Yuyin Zhou

TL;DR

H-SAM introduces a prompt-free, two-stage hierarchical decoding framework to adapt Meta’s Segment Anything Model (SAM) for medical image segmentation. By generating its own internal probabilistic masks to guide a secondary, fine-grained decoding stage, H-SAM eliminates the need for manual human prompts and outperforms state-of-the-art semi-supervised models using only a fraction of labeled data.

What Problem Does This Paper Address?

The Segment Anything Model (SAM) has revolutionized computer vision with its impressive zero-shot segmentation capabilities. However, when applied to medical imagery (like CT or MR scans), SAM’s performance drops significantly due to the stark domain shift from natural images.

To fix this, researchers usually take one of two paths: fully fine-tuning the model (which is computationally expensive and risks overfitting on small medical datasets) or relying on high-quality bounding boxes or point prompts during inference. Unfortunately, requiring medical experts to manually generate these prompts in a clinical workflow is time-consuming and prone to variability. While "prompt-free" versions of SAM exist, they typically yield inferior results because they lack the localized guidance that prompts naturally provide. H-SAM bridges this gap by enabling SAM to generate its own internal guidance mechanism without human intervention.

Methods

H-SAM keeps SAM’s powerful image encoder frozen to preserve its pre-trained knowledge, adding efficient Low-Rank Adaptation (LoRA) layers to handle the domain shift. The core innovation lies in its Hierarchical Mask Decoder, which splits the segmentation task into two distinct stages:

  1. Stage 1 (Prior Generation): The model uses SAM’s original lightweight decoder to generate a rough, "prior" probabilistic mask of the target organs or lesions.
  2. Stage 2 (Refinement): This prior mask is fed into an intricate, secondary decoding process featuring two novel attention mechanisms:
  3. Class-Balanced Mask-Guided Self-Attention (CMAttn): Medical images often suffer from severe class imbalance (e.g., a massive liver versus a tiny gallbladder). CMAttn injects Gaussian noise into the mask features—scaled inversely to how frequently a class appears—to boost the representation of rare "tail" categories.
  4. Learnable Mask Cross-Attention: Traditional mask attention binarizes predictions into hard 0s and 1s, which kills gradients and discards nuance. H-SAM uses the raw, soft probabilistic map from Stage 1 to spatially modulate cross-attention, focusing the model's attention on foreground regions while allowing gradients to flow smoothly during training.

Finally, a U-Net-inspired Hierarchical Pixel Decoder connects the two stages via skip connections, ensuring that fine-grained, localized spatial details aren't lost during upsampling.

Figure 2. The H-SAM framework integrates a LoRA-adapted image encoder and a sophisticated 2-stage hierarchical decoder. We finetune the prompt encoder with default embeddings under a prompt-free setting. A key innovation lies in our hierarchical mask decoder, which strategically utilizes predictions from the stage-1 decoder as priors to achieve nuanced segmentation with 2 implementations: Class- Balanced Mask-Guided Self-Attention (CMAttn), and Learnable Mask Cross-Attention. And a hierarchical pixel decoder is employed to complement the enriched object queries derived from the transformer decoder.

Datasets

The authors evaluated H-SAM across three distinct medical segmentation benchmarks:

  • Synapse Multi-Organ CT: 3,779 axial abdominal CT slices used to segment eight different organs (aorta, gallbladder, spleen, kidneys, liver, pancreas, and stomach).
  • Left Atrial (LA) Dataset: 2018 Atrial Segmentation Challenge MRI scans (80 for training, 20 for evaluation).
  • PROMISE12: A 3D transversal T2-weighted MR image dataset focused on prostate gland segmentation.

Key Insights and Ideas

  • Self-Prompting via Hierarchical Decoding: Instead of fighting the prompt-free performance penalty, H-SAM treats the first-stage output as an unprompted "rough draft" that acts exactly like an internal prompt for the second stage.
  • Soft Masks Keep Gradients Alive: Binarizing masks during cross-attention creates a optimization bottleneck. By keeping the mask probabilistic, the network can backpropagate errors effectively, leading to faster convergence and better edge delineation.
  • Data-Economic Superiority: One of the most striking findings is that H-SAM can beat semi-supervised models without using any unlabeled data. It maximizes the utility of limited labeled slices by structurally forcing the network to learn robust medical priors.

Key Results

H-SAM demonstrated exceptional data efficiency and accuracy in few-shot scenarios:

  • Synapse CT (Few-Shot): Using just 10% of the training slices, H-SAM achieved a 80.35% Mean Dice score, outperforming the previous best prompt-free variant (SAMed) by nearly 5%.
  • Left Atrial Dataset: Trained on only 4 labeled scans (5% of the dataset), H-SAM achieved a 89.22% Mean Dice score, outperforming state-of-the-art semi-supervised methods (like BCP) that utilized the remaining 76 unlabeled scans.
  • PROMISE12: With only 3 labeled cases, H-SAM hit an 87.27% Mean Dice score, gapping the semi-supervised baseline (MLB-Seg) by over 10%.
Figure 5. The qualitative results of H-SAM and other SAM vari- ants, including SAMed, SAM Adapter, and AutoSAM.

Limitations and Future Work

While H-SAM is highly effective, it is susceptible to cascading errors. Because Stage 2 relies heavily on the prior generated in Stage 1, a catastrophic failure in the first stage (e.g., completely missing an organ or misidentifying a background region as a kidney) can mislead the secondary refinement process. The authors note a few such failure cases in their supplementary material. Future work will likely focus on making the hierarchical coupling more robust to noisy first-stage priors.

Summary updated

BibTeX
@misc{cheng2024unleashing,
  author = {Zhiheng Cheng and Qingyue Wei and Hongru Zhu and Yan Wang and Liangqiong Qu and Wei Shao and Yuyin Zhou},
  title = {{Unleashing the Potential of SAM for Medical Adaptation via Hierarchical Decoding}},
  year = {2024},
  eprint = {2403.18271},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2403.18271},
}
Figure