Deep Instruction Tuning for Segment Anything Model

Xiaorui Huang, Gen Luo, Chaoyang Zhu, Bo Tong, Yiyi Zhou, Xiaoshuai Sun, Rongrong Ji · DOI

Abstract

The Segment Anything Model (SAM) has emerged as a foundational tool in computer vision, demonstrating remarkable versatility across various image segmentation tasks. However, while SAM excels when guided by points or bounding boxes, its performance significantly degrades when faced with text-based instructions, such as those found in Referring Image Segmentation (RIS). This paper identifies the primary cause of this deficiency as the "shallow fusion" scheme within SAM’s default lightweight mask decoder. To overcome this, we propose Deep Instruction Tuning (DIT), a method that transforms SAM’s image encoder into a stand-alone vision-language learner. We introduce two variants: an end-to-end (E-DIT) approach and a layer-wise (L-DIT) approach. Our results demonstrate that DIT allows SAM to achieve state-of-the-art performance on competitive RIS benchmarks with minimal architectural modifications and significantly lower training costs than existing specialized models.

Introduction

Since its release, the Segment Anything Model (SAM) has set a new standard for promptable image segmentation. By training on over a billion masks, SAM has developed a robust understanding of object boundaries and spatial hierarchies. Yet, a notable gap exists in its capabilities: text-guided segmentation. In Referring Image Segmentation (RIS), where a model must identify an object based on a natural language description (e.g., "the person in the red shirt behind the table"), SAM often fails to resolve the complex linguistic relationships required for accurate localization.

This research argues that the bottleneck is architectural. In the original SAM framework, text prompts are processed by a separate encoder and only interact with visual features at the final stage within a lightweight mask decoder. This "shallow fusion" prevents the model from utilizing its massive visual backbone to reason about the text during the feature extraction process. To address this, we propose Deep Instruction Tuning (DIT), which integrates linguistic information directly into the Vision Transformer (ViT) layers of SAM.

Methodology: Deep Instruction Tuning (DIT)

The core philosophy of DIT is to treat SAM’s existing visual encoder as a multi-modal processor rather than a purely visual one. We propose two distinct methods for this integration:

1. End-to-End DIT (E-DIT)

In the E-DIT configuration, text instructions are first converted into tokens. These tokens are then concatenated with the initial image patches at the very first layer of SAM’s ViT encoder. This allows the text and image features to interact via self-attention throughout the entire depth of the network. By the time the features reach the mask decoder, they are already "text-aware."

2. Layer-wise DIT (L-DIT)

L-DIT takes the integration a step further. Instead of only introducing text at the beginning, text features are projected and injected into every single layer of the image encoder. This approach helps bridge the "modality gap" more effectively, as the linguistic information can adapt to different levels of visual abstraction—from low-level edges in early layers to complex semantic objects in deeper layers.

Crucially, both methods require minimal structural changes to SAM, avoiding the need for the heavy, specialized fusion branches typically found in other vision-language models.

Experimental Evaluation

We evaluated our DIT-enhanced SAM on three primary Referring Image Segmentation benchmarks:

  • RefCOCO: A large-scale dataset featuring interactive expressions.
  • RefCOCO+: A dataset that excludes absolute spatial terms, forcing the model to rely on appearance and attribute descriptions.
  • RefCOCOg: A dataset containing longer, more complex "non-interactive" descriptions.

Performance and Efficiency

The results were definitive. E-DIT improved SAM’s performance on RefCOCO by a massive margin of +11.8% mIoU. The more advanced L-DIT, utilizing the ViT-H backbone, achieved a state-of-the-art (SOTA) score of 76.18% oIoU on RefCOCO. This performance surpassed existing models specifically designed for RIS, despite DIT requiring significantly less training data and computational expenditure.

Layer-Specific Insights

Qualitative analysis of the attention maps revealed that different layers of the encoder specialize in different aspects of the text instruction. Initial layers tend to focus on nouns and entities, middle layers resolve comparative spatial words, and the deepest layers refine the segmentation based on specific attributes like color or digital patterns.

Conclusion

Deep Instruction Tuning effectively bridges the gap between SAM’s powerful segmentation capabilities and the nuances of natural language. By moving from shallow fusion to deep, layer-wise interaction, we transform SAM into a highly capable vision-language learner without the need for complex architectural redesigns. While challenges remain—such as balancing dynamic text prompts with static learnable tokens—DIT provides a scalable and efficient path forward for multi-modal instruction tuning in foundational vision models.

Summary updated

BibTeX
@inproceedings{huang2024deep,
  author = {Xiaorui Huang and Gen Luo and Chaoyang Zhu and Bo Tong and Yiyi Zhou and Xiaoshuai Sun and Rongrong Ji},
  title = {{Deep Instruction Tuning for Segment Anything Model}},
  booktitle = {ACM Multimedia},
  year = {2024},
  doi = {10.1145/3664647.3680571},
}
Figure