SlimSAM: 0.1% Data Makes Segment Anything Slim

Zigeng Chen, Gongfan Fang, Xinyin Ma, Xinchao Wang

TL;DR

SlimSAM is a hyper-efficient compression technique for the Segment Anything Model (SAM) that requires just 0.1% of the original training data to produce a high-performance, lightweight model. By alternating between pruning and distilling specific sub-structures and using a novel "Disturbed Taylor" importance metric, it slashes SAM’s parameter count to 1.4% of the original while maintaining impressive segmentation accuracy.

The Challenge of Shrinking SAM

The Segment Anything Model (SAM) revolutionized computer vision with its remarkable "zero-shot" segmentation capabilities. However, its primary version (SAM-H) is massive, making it nearly impossible to deploy on edge devices like smartphones or drones.

Existing attempts to shrink SAM usually involve training a new, lightweight architecture from scratch (e.g., MobileSAM, EfficientSAM). This approach creates a difficult trade-off: training from scratch requires millions of images and massive compute power. Conversely, traditional "pruning"—simply cutting out redundant parts of the existing model—requires less data but usually leads to a catastrophic drop in performance when compressing the model to a fraction of its original size. SlimSAM aims to bridge this gap, achieving extreme compression with minimal data and high performance.

Core Innovations

To make SAM "slim" without losing its "intelligence," the authors introduce two primary methods:

1. Alternate Slimming Framework

Instead of pruning the entire model in one go, SlimSAM decomposes the Vision Transformer (ViT) blocks into two decoupled sub-structures:

  • Embedding: The output dimensions of each block.
  • Bottleneck: The intermediate features within the block.

The framework alternates between pruning one structure and distilling (aligning) the other. This step-by-step approach prevents the steep performance degradation typically seen in single-step pruning and allows for intermediate feature alignment even when dimensions are changing.

Alternate Slimming Framework applied to SAM

2. Disturbed Taylor Pruning

Pruning requires an "importance score" to decide which weights to keep. Standard methods (like Taylor importance) usually require ground-truth labels. However, since SlimSAM uses distillation (learning directly from the original, larger SAM), there are no hard labels available.

To solve this, the authors add a tiny amount of Gaussian noise to the original model's embeddings. They then calculate gradients based on how the model reacts to this "disturbance." This aligns the pruning objective perfectly with the distillation target, all without needing a single human-provided label.

Performance comparison of Alternate Slimming vs. One Step pruning

Key Results and Insights

SlimSAM achieves state-of-the-art results in the "tiny SAM" category, proving that knowledge inheritance is vastly more data-efficient than training from scratch.

  • Extreme Compression: The SlimSAM-77 variant reduces parameters to just 9.1M (1.4% of SAM-H) and computational cost to 23G MACs (0.8% of SAM-H).
  • High Accuracy: Despite its tiny size, SlimSAM-77 maintains a 67.40% MIoU, outperforming other models like EdgeSAM and MobileSAM.
  • Unprecedented Data Efficiency: The model was trained using only 10,000 unlabeled images from the SA-1B dataset. This is over 10 times less data than any other existing SAM compression method and 1,100 times less data than EfficientSAM.
  • Hardware Speedup: On an NVIDIA Titan RTX, SlimSAM-77 achieves an 8.6x inference speedup compared to the original SAM-H.

Limitations and Future Work

While highly effective, the authors acknowledge a few key constraints. Because SlimSAM relies on distilling knowledge from the original SAM, its performance is inherently capped by the teacher model; it cannot easily surpass the original's accuracy. Additionally, while 10k images yield great results, increasing the data volume could potentially lead to "lossless" compression, where the tiny model matches the big model perfectly. Future research will likely focus on breaking this performance ceiling while maintaining the exceptionally low parameter counts and training costs established by SlimSAM.

Summary updated

BibTeX
@inproceedings{chen2024slimsam,
  author = {Zigeng Chen and Gongfan Fang and Xinyin Ma and Xinchao Wang},
  title = {{SlimSAM: 0.1\% Data Makes Segment Anything Slim}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=ZG84y6a7ge},
}
Figure