Segment Anything in High Quality

Lei Ke, Mingqiao Ye, Martin Danelljan, Yifan liu, Yu-Wing Tai, Chi-Keung Tang, Fisher Yu

Introduction

Meta’s Segment Anything Model (SAM) represented a paradigm shift in computer vision, demonstrating that a foundation model trained on 1.1 billion masks could segment nearly any object through simple prompting. Despite its impressive zero-shot generalization, SAM often struggles with "coarseness." Because it was trained largely on automatically generated masks, it frequently fails to capture high-precision boundaries and overlooks intricate structures like thin wires, insect legs, or fine mesh.

To address this, researchers introduced HQ-SAM, a lightweight upgrade designed to provide SAM with a "fine-tip pen." By adding less than 0.5% more parameters and requiring only four hours of training, HQ-SAM produces high-fidelity masks while fully preserving the original model's legendary versatility.

The Problem: The Precision Gap

While SAM is highly effective at identifying general object shapes, its output often lacks the detail required for professional photo editing or high-accuracy automated annotation. This limitation stems from two factors: the noise inherent in the massive SA-1B dataset and an architecture that doesn't fully leverage low-level image features for final mask refinement. The challenge for the researchers was to improve this detail without destroying the "world knowledge" that makes SAM a foundation model.

Methodology: A Surgical Adaptation

HQ-SAM introduces a minimal, surgical adaptation to the original SAM architecture. The approach is defined by two primary innovations:

  1. The HQ-Output Token: In the original SAM, output tokens are responsible for mask prediction. HQ-SAM injects a new, learnable High-Quality Output Token into the existing mask decoder. This token is specifically optimized for high-fidelity predictions. Crucially, the original SAM weights remain frozen during training, preventing "catastrophic forgetting" and ensuring the model retains its broad segmentation capabilities.
  2. Global-Local Feature Fusion: High-quality boundaries require a combination of semantic context (identifying the object) and low-level detail (locating the edge). HQ-SAM achieves this by fusing the mask decoder's features with both "early" (low-level/edge-heavy) and "final" (high-level/semantic) features from SAM’s ViT encoder.

By training only the new token, a small Multi-Layer Perceptron (MLP), and a fusion block, the authors maintained high efficiency. HQ-SAM operates at approximately 96% of the original SAM’s speed.

Data Strategy: Quality Over Quantity

The researchers hypothesized that SAM’s coarseness was a direct result of its training data. To refine the model, they moved away from the billion-scale but noisy SA-1B dataset and curated HQSeg-44K.

  • HQSeg-44K: This dataset consists of 44,320 extremely fine-grained masks, merging six existing high-quality datasets (including DIS, ThinObject-5K, and HR-SOD). It covers over 1,000 semantic classes.
  • Evaluation: The model was rigorously tested across 10 diverse datasets, including COCO, LVIS, and specialized benchmarks like HQ-YTVIS (video) and BIG (high-resolution).

This strategy suggests that for boundary refinement, the accuracy of the ground truth is significantly more important than the sheer scale of the dataset.

Key Results and Insights

HQ-SAM demonstrates that foundation models can be significantly improved with minimal additional training. Key findings include:

  • Superior Precision: On the DIS (Dichotomous Image Segmentation) dataset, HQ-SAM improved the boundary IoU (mBIoU) from 52.8 to 70.4—a substantial leap in edge accuracy.
  • Zero-Shot Success: In transfer tests on tasks the model was not specifically trained for, HQ-SAM consistently outperformed the base SAM across eight different benchmarks.
  • Efficiency: Training is remarkably fast, taking only four hours on eight RTX 3090 GPUs. For the end-user, the model size increase is negligible (less than 0.5%).
  • Robustness: The model is significantly more resilient to "noisy" input boxes—prompts that are not perfectly centered or sized—compared to the original SAM.

Limitations and Future Outlook

While HQ-SAM is a major advancement, some challenges remain. The model still relies on SAM’s heavy ViT-H encoder, which limits real-time performance on mobile devices (though a "Light HQ-SAM" variant using TinyViT has been introduced to address this). Additionally, the model can still struggle in extremely dark environments or with ultra-thin structures like fine metal rods.

Ultimately, HQ-SAM provides a blueprint for upgrading foundation models: by using a minimal adaptation strategy and high-quality data, researchers can enhance specific capabilities without the need for massive, expensive re-training.

Summary updated

BibTeX
@inproceedings{ke2023segment,
  author = {Lei Ke and Mingqiao Ye and Martin Danelljan and Yifan liu and Yu-Wing Tai and Chi-Keung Tang and Fisher Yu},
  title = {{Segment Anything in High Quality}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2023},
  url = {https://openreview.net/forum?id=RA7ND878XP},
}
Figure