SAM2-Adapter: Evaluating & Adapting Segment Anything 2 in Downstream Tasks: Camouflage, Shadow, Medical Image Segmentation, and More

Tianrun Chen, Ankang Lu, Lanyun Zhu, Chaotao Ding, Chunan Yu, Deyi Ji, Zejian Li, Lingyun Sun, Papa Mao, Ying Zang

TL;DR

While Segment Anything 2 (SAM2) excels at open-world segmentation, it struggles with domain-specific, low-level structural tasks like shadow detection, camouflage camouflage detection, and medical imaging when used out of the box. SAM2-Adapter is the first parameter-efficient adaptation framework designed specifically for SAM2's multi-resolution hierarchical backbone, injecting task-specific visual cues into frozen transformer layers to achieve new state-of-the-art results across these challenging domains.

What Problem Does This Paper Address?

Foundation models like Meta's SAM and SAM2 are trained on massive datasets to segment generic visual concepts. However, foundation models have a known blind spot: specialized or low-contrast downstream tasks where foreground and background seamlessly merge.

In camouflaged object detection, shadow segmentation, and polyp detection in endoscopy, visual cues are subtle (relying on high-frequency edges, delicate textures, or faint lighting boundaries) rather than salient object semantics. Surprisingly, the authors find that out-of-the-box SAM2 performs poorly on these tasks without domain-specific guidance—frequently producing degraded or empty masks. Fine-tuning the entire model is computationally heavy and risks catastrophic forgetting; thus, the authors address how to effectively steer SAM2's rich pretrained representations toward specialized vision tasks using lightweight adapters.

Methods

SAM2-Adapter preserves SAM2's core visual representation while injecting domain knowledge through compact, trainable modules:

  • Frozen Backbone, Tunable Decoder: The MAE pretrained Hiera image encoder is kept completely frozen. The mask decoder is initialized from SAM2 weights and fine-tuned during training without relying on external prompt inputs (such as points or bounding boxes).
  • Multi-Stage Hierarchical Adapters: Unlike original SAM’s isotropic ViT backbone, SAM2 uses a 4-stage hierarchical Transformer (Hiera) with varying feature resolutions. SAM2-Adapter places four distinct adapters corresponding to each stage. Within any given stage, the adapter parameters are shared across that stage's transformer layers.
  • Prompt Generation Architecture: Each adapter consists of two linear layers with a GELU non-linearity in between: $$\mathcal{P}^i = \text{MLP}_{\text{up}}(\text{GELU}(\text{MLP}_{\text{tune}}^i(F_i)))$$ Here, $\text{MLP}_{\text{tune}}^i$ extracts task-specific prompt vectors, while $\text{MLP}_{\text{up}}$ is shared across adapters to map prompts into the transformer's feature dimension before attaching to the transformer layers.

  • Task-Specific Visual Prior Injection ($F_i$): Domain knowledge is introduced by combining patch embeddings ($F_{pe}$) with high-frequency Fourier components ($F_{hfc}$), feeding critical texture and boundary priors directly into the network.

Datasets

The authors evaluated the method across three distinct application domains:

  • Camouflaged Object Detection (COD):
  • Training: Combined training sets of COD10K (3,040 images) and CAMO (1,000 images).
  • Testing: COD10K test set (2,026 images), CAMO test set (250 images), and CHAMELEON (76 images).
  • Shadow Detection:
  • ISTD dataset (1,330 training images, 540 test images).
  • Medical Image (Polyp) Segmentation:
  • Kvasir-SEG dataset, evaluated under the Medico multimedia task split at MediaEval 2020.

Note: No new datasets were introduced; all benchmarks are established downstream evaluation standards.

Key Insights and Ideas

  • SAM2 is Not Automatically Better in the Wild: Out of the box, SAM2's zero-shot capability on these dense, low-level structural tasks is notably worse than original SAM (e.g., scoring only 0.200 mDice on polyp segmentation and a 50.81 Balance Error Rate on shadow detection). Without interactive prompts, the foundation model lacks the inductive bias to understand concepts like "shadows" or "concealed animals."
  • Matching Adapter Topology to Backbone Architecture: The shift from SAM’s flat ViT to SAM2’s multi-resolution Hiera encoder necessitates multi-level feature injection. Assigning dedicated adapters to each resolution stage allows task-specific prompts to guide both high-level semantics and fine-grained spatial details.
  • Explicit High-Frequency Cues Matter: Simply relying on deep transformer features often misses subtle edge variations. Injecting frequency-domain components ($F_{hfc}$) directly into the adapter provides the missing inductive bias required for finding hidden contours.

Key Results

SAM2-Adapter sets new state-of-the-art benchmarks across the board:

Task / Dataset Key Metric Standalone SAM2 SAM-Adapter SAM2-Adapter (Ours)
COD: CHAMELEON S-measure ($S_\alpha \uparrow$) / MAE $\downarrow$ 0.359 / 0.357 0.896 / 0.033 0.915 / 0.018
COD: CAMO S-measure ($S_\alpha \uparrow$) / MAE $\downarrow$ 0.350 / 0.311 0.847 / 0.070 0.855 / 0.051
COD: COD10K S-measure ($S_\alpha \uparrow$) / MAE $\downarrow$ 0.429 / 0.218 0.883 / 0.025 0.899 / 0.018
Shadow: ISTD Balance Error Rate (BER $\downarrow$) 50.81 1.43 1.43 (beats FDRNet's 1.55)
Medical: Kvasir-SEG Mean Dice (mDice $\uparrow$) / mIoU $\uparrow$ 0.200 / 0.029 0.850 / 0.776 0.873 / 0.806

Qualitatively, SAM2-Adapter delineates razor-sharp polyp borders and complete camouflaged animal silhouettes where baseline foundation models output noise or partial artifacts.

Limitations and Future Work

  • Dependence on Heuristic Priors: The visual knowledge injection relies on predefined hand-crafted cues (such as FFT high-frequency components and patch embeddings). Automatic learning or multi-modal prompt generation (e.g., text descriptions) remains unexplored.
  • Evaluated Primarily on Static 2D Images: Even though SAM2 was purpose-built with memory modules for video segmentation, SAM2-Adapter focuses strictly on static 2D image tasks. Extending multi-stage adapters into SAM2's temporal memory modules for video tracking/video camouflage detection represents an obvious next frontier.

Summary updated

BibTeX
@inproceedings{chen2025sam,
  author = {Tianrun Chen and Ankang Lu and Lanyun Zhu and Chaotao Ding and Chunan Yu and Deyi Ji and Zejian Li and Lingyun Sun and Papa Mao and Ying Zang},
  title = {{SAM2-Adapter: Evaluating \& Adapting Segment Anything 2 in Downstream Tasks: Camouflage, Shadow, Medical Image Segmentation, and More}},
  booktitle = {FM-Wild @ ICLR},
  year = {2025},
  url = {https://openreview.net/forum?id=iBoABx5wjA},
}
Figure