EfficientSAM: Leveraged Masked Image Pretraining for Efficient Segment Anything

Yunyang Xiong, Bala Varadarajan, Lemeng Wu, Xiaoyu Xiang, Fanyi Xiao, Chenchen Zhu, Xiaoliang Dai, Dilin Wang, Fei Sun, Forrest N. Iandola, Raghuraman Krishnamoorthi, Vikas ChandraCVPR 2023

Abstract

Segment Anything Model (SAM) has emerged as a powerful tool for numerous vision applications. A key component that drives the impressive performance for zero-shot transfer and high versatility is a super large Transformer model trained on the extensive high-quality SA-1B dataset. While beneficial, the huge computation cost of SAM model has limited its applications to wider real-world applications. To address this limitation, we propose EfficientSAMs, light-weight SAM models that exhibit decent performance with largely reduced complexity. Our idea is based on leveraging masked image pretraining, SAMI, which learns to reconstruct features from the SAM image encoder for effective visual representation learning. Further, we take SAMI-pretrained light-weight image encoders and mask decoders to build EfficientSAMs, and finetune the models on SA-1B for the segment anything task. We perform evaluations on multiple vision tasks including image classification, object detection, instance segmentation, and semantic segmentation, and find that our proposed pretraining method, SAMI, consistently outperforms other masked image pretraining methods. On segment anything tasks such as zero-shot instance segmentation, our EfficientSAMs with SAMI-pretrained lightweight image encoders perform favorably with a significant gain (e.g., ~4 AP on COCO/LVIS) over other fast SAM models.

Introduction

The original Segment Anything Model (SAM) was a breakthrough in computer vision, capable of segmenting any object in an image based on simple prompts like a click or a box. However, its "brain"—a massive Vision Transformer (ViT-H) with 632 million parameters—is a computational heavyweight. This size makes SAM difficult to deploy in real-time scenarios, on mobile devices, or in high-throughput industrial pipelines.

EfficientSAM introduces a high-performance, lightweight version of SAM that is 20 times smaller and faster while retaining nearly all of its accuracy. By using a novel pretraining strategy called SAMI, the researchers have made state-of-the-art "segment anything" capabilities viable for real-time applications and edge devices.

Performance trade-off and high-level pipeline of EfficientSAM.

Methods

The authors propose a two-stage approach centered on a new pretraining technique called SAMI (SAM-leveraged Masked Image pretraining).

  1. SAMI Pretraining: Instead of the standard approach of training a model to reconstruct missing pixels in an image (like a standard Masked Autoencoder), SAMI trains a lightweight encoder (like ViT-Tiny or ViT-Small) to reconstruct the feature embeddings of the original, frozen SAM ViT-H model. Essentially, the small model learns to "think" like the big model by predicting its internal representations for masked-out parts of an image.
  2. Cross-Attention Decoder: They use a specialized decoder where masked tokens act as queries to extract information from unmasked tokens via cross-attention, making the reconstruction process more efficient.
  3. EfficientSAM Construction: Once the small encoder is pretrained to mimic the big SAM's features, it is paired with SAM’s standard prompt-guided mask decoder. The entire system is then finetuned on the massive SA-1B dataset (11 million images, 1 billion masks) to specialize it for the "segment anything" task.
Detailed architecture of SAMI pretraining and EfficientSAM construction.

Key Insights and Results

  • Feature Reconstruction is Key: Reconstructing the high-level features of a powerful teacher model (SAM) is far more effective for downstream tasks than reconstructing raw pixels. It forces the small model to capture the semantic essence of the image that the large model has already mastered.
  • Massive Speedup and Shrinkage: EfficientSAM-S reduces the inference time of the original SAM by ~20x. The parameter count drops from 636M (SAM) to just 25M (EfficientSAM-S) and 10M (EfficientSAM-Ti). On an NVIDIA A100 GPU, EfficientSAM-Ti can process 54 images per second, compared to just 2 images per second for the original SAM.
  • High Fidelity Performance: On the COCO benchmark, EfficientSAM-S achieves 44.4 AP, coming remarkably close to the original SAM’s 46.5 AP. It outperforms other "fast" versions like MobileSAM and FastSAM by a significant margin (roughly 4 AP higher on COCO/LVIS).
  • Generalization Beyond Segmentation: Because the SAMI-pretrained encoders learn such rich representations, they actually outperform other state-of-the-art pretraining methods on general tasks like ImageNet-1K classification and object detection.

Limitations and Future Work

While highly accurate, EfficientSAM can occasionally produce "noisy" or less precise masks compared to the full-sized ViT-H version in complex scenes. Additionally, the method relies on having a pre-existing, high-quality "teacher" model. The researchers suggest that this "feature reconstruction" pretraining could be applied to other large foundation models in language or multi-modal tasks to create efficient versions for edge deployment.

Summary updated

BibTeX
@inproceedings{xiong2023efficientsam,
  author = {Yunyang Xiong and Bala Varadarajan and Lemeng Wu and Xiaoyu Xiang and Fanyi Xiao and Chenchen Zhu and Xiaoliang Dai and Dilin Wang and Fei Sun and Forrest N. Iandola and Raghuraman Krishnamoorthi and Vikas Chandra},
  title = {{EfficientSAM: Leveraged Masked Image Pretraining for Efficient Segment Anything}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2023},
  url = {https://openreview.net/forum?id=Yc2sBEKvxU},
}
Figure