Continual Learning for Segment Anything Model Adaptation

Jinglong Yang, Yichen Wu, Jun Cen, Wenjian Huang, Hong Wang, Jianguo ZhangarXiv 2024 · DOI

Introduction

The Segment Anything Model (SAM) has revolutionized general image segmentation. However, its performance often falters when applied to specialized "long-tail" domains, such as medical imaging or industrial defect detection. While one-step adaptation methods exist, they fail to address the dynamic nature of real-world data streams. When SAM is fine-tuned sequentially on new tasks, it suffers from catastrophic forgetting, losing its ability to perform previously learned tasks. This paper introduces the CoSAM benchmark and the MoDA (Mixture of Domain Adapters) framework to enable stable, continual adaptation for SAM.

The MoDA Framework

The proposed MoDA architecture addresses the limitations of applying standard Continual Learning (CL) strategies to SAM. Traditional CL methods often rely on well-separated task features in the encoder's latent space, which SAM's prompt-based encoder does not naturally produce.

MoDA introduces two primary innovations:

  1. Global Feature & Assistant Tokens (GFT & GAT): These tokens interact with image patches across the transformer layers to extract a "task-specific signature." This signature acts as a query to identify the domain of the input image.
  2. Task-Specific Adapter Pool: MoDA maintains a set of lightweight adapters. During inference, the query generated by the GFT/GAT modules automatically routes the input to the appropriate adapter.

This modular approach allows MoDA to be integrated into existing SAM variants like HQ-SAM or SAM-Adapter, transforming them from one-step learners into effective continual learners.

Performance overview: (a) Radar chart showing IoU across diverse tasks; (b) Comparison of final IoU (bars) and forgetting rate (line) for various methods.

The CoSAM Benchmark

To evaluate continual adaptation, the authors established the CoSAM benchmark, comprising eight distinct tasks from five diverse domains:

  • Industrial: BSData (surface defects) and RSDD (railway track defects).
  • Anomaly Detection: MVTec (three distinct object groups).
  • Specialized Vision: CAMO (camouflaged objects) and Polyp (medical colonoscopy).

Bridging the "Encoder Gap"

A critical insight of this research is the "Encoder Gap." Unlike models pretrained on ImageNet, SAM’s encoder does not naturally cluster different task domains. This lack of inherent structure causes traditional prompt-based CL methods to fail because they cannot distinguish between tasks based on encoder features alone. MoDA overcomes this by explicitly learning task-specific signatures through its global token mechanism.

t-SNE visualization of feature spaces: (a) Original SAM encoder, (b) Baseline adaptation, and (c) MoDA. MoDA significantly improves task-specific feature clustering.

Experimental Results

The integration of MoDA yields substantial improvements across all metrics:

  • Performance Gains: Adding MoDA to a standard decoder-tuning baseline resulted in a 28.5% increase in Last-IoU (Intersection over Union).
  • Forgetting Mitigation: MoDA effectively eliminates catastrophic forgetting. In the HQ-SAM configuration, the forgetting measure (FF-IoU) was reduced from 4.9% to just 0.28%.
  • Zero-Shot Preservation: Crucially, MoDA preserves SAM's original capabilities. On the COCO dataset (natural images), HQ-SAM + MoDA achieved 77.6 IoU, nearly matching the original SAM's 78.1 IoU, whereas naive fine-tuning often causes significant degradation.
  • Robustness: The system proved robust to task-ordering, maintaining stable performance regardless of the sequence in which domains were introduced.

Conclusion

MoDA represents a significant step forward in making foundation models like SAM practical for evolving, specialized environments. By combining global task identification tokens with a modular adapter pool, it effectively balances the acquisition of new knowledge with the preservation of existing capabilities. Future research may focus on reducing the reliance on small memory buffers for rehearsal and scaling the adapter pool to handle even larger numbers of tasks.

Summary updated

BibTeX
@misc{yang2024continual,
  author = {Jinglong Yang and Yichen Wu and Jun Cen and Wenjian Huang and Hong Wang and Jianguo Zhang},
  title = {{Continual Learning for Segment Anything Model Adaptation}},
  year = {2024},
  eprint = {2412.06418},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2412.06418},
}
Figure