--- title: Repvit Sam emoji: 🚀 colorFrom: yellow colorTo: yellow sdk: gradio sdk_version: 4.8.0 app_file: app.py pinned: false license: mit --- # [RepViT-SAM: Towards Real-Time Segmenting Anything]() Official PyTorch implementation of **RepViT-SAM**, from the following paper: [RepViT-SAM: Towards Real-Time Segmenting Anything]().\ Ao Wang, Hui Chen, Zijia Lin, Hengjun Pu, and Guiguang Ding\ [[`arXiv`]()]
Abstract Segment Anything Model (SAM) has shown impressive zero-shot transfer performance for various computer vision tasks recently. However, its heavy computation costs remain daunting for practical applications. MobileSAM proposes to replace the heavyweight image encoder in SAM with TinyViT by employing distillation, which results in a significant reduction in computational requirements. However, its deployment on resource-constrained mobile devices still encounters challenges due to the substantial memory and computational overhead caused by self-attention mechanisms. Recently, RepViT achieves the state-of-the-art performance and latency trade-off on mobile devices by incorporating efficient architectural designs of ViTs into CNNs. Here, to achieve real-time segmenting anything on mobile devices, following, we replace the heavyweight image encoder in SAM with RepViT model, ending up with the RepViT-SAM model. Extensive experiments show that RepViT-SAM can enjoy significantly better zero-shot transfer capability than MobileSAM, along with nearly $10\times$ faster inference speed.

## Installation ```bash git clone https://github.com/THU-MIG/RepViT cd sam && pip install -e . # download pretrained checkpoint mkdir weights && cd weights wget https://github.com/THU-MIG/RepViT/releases/download/v1.0/repvit_sam.pt ``` ## Demo Our Hugging Face demo is [here](https://huggingface.co/spaces/jameslahm/repvit-sam) ``` python app/app.py ``` ## CoreML export Please refer to [coreml_example.ipynb](https://github.com/THU-MIG/RepViT/blob/main/sam/notebooks/coreml_example.ipynb) ## Latency comparisons Comparison between RepViT-SAM and others in terms of latency. The latency (ms) is measured with the standard resolution of 1024 x 1024 on iPhone 12 and Macbook M1 Pro by Core ML Tools. OOM means out of memory.
Platform Image encoder Mask decoder
iPhone 48.9ms OOM OOM 11.6ms
Macbook 44.8ms 482.2ms 6249.5ms 11.8ms
## Acknowledgement The code base is partly built with [SAM](https://github.com/facebookresearch/segment-anything) and [MobileSAM](https://github.com/ChaoningZhang/MobileSAM). Thanks for the great implementations! ## Citation If our code or models help your work, please cite our paper: ```BibTeX @misc{wang2023repvit, title={RepViT: Revisiting Mobile CNN From ViT Perspective}, author={Ao Wang and Hui Chen and Zijia Lin and Hengjun Pu and Guiguang Ding}, year={2023}, eprint={2307.09283}, archivePrefix={arXiv}, primaryClass={cs.CV} } ```