Spaces:
Running
on
A10G
Running
on
A10G
title: Repvit Sam | |
emoji: π | |
colorFrom: yellow | |
colorTo: yellow | |
sdk: gradio | |
sdkVersion: 4.36.0 | |
app_file: app.py | |
pinned: false | |
license: mit | |
# [RepViT-SAM: Towards Real-Time Segmenting Anything](https://arxiv.org/abs/2312.05760) | |
Official PyTorch implementation of **RepViT-SAM**, from the following paper: | |
[RepViT-SAM: Towards Real-Time Segmenting Anything](https://arxiv.org/abs/2312.05760).\ | |
Ao Wang, Hui Chen, Zijia Lin, Hengjun Pu, and Guiguang Ding\ | |
[[`arXiv`](https://arxiv.org/abs/2312.05760)] | |
<details> | |
<summary> | |
<font size="+1">Abstract</font> | |
</summary> | |
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. | |
</details> | |
<br/> | |
## 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. | |
<table class="tg"> | |
<thead> | |
<tr> | |
<th class="tg-c3ow" rowspan="1">Platform</th> | |
<th class="tg-c3ow" colspan="3">Image encoder</th> | |
<th class="tg-c3ow" rowspan="1">Mask decoder</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td class="tg-c3ow">iPhone</td> | |
<td class="tg-c3ow"><b>48.9ms</b></td> | |
<td class="tg-c3ow">OOM</td> | |
<td class="tg-c3ow">OOM</td> | |
<td class="tg-c3ow">11.6ms</td> | |
</tr> | |
<tr> | |
<td class="tg-c3ow">Macbook</td> | |
<td class="tg-c3ow"><b>44.8ms</b></td> | |
<td class="tg-c3ow">482.2ms</td> | |
<td class="tg-c3ow">6249.5ms</td> | |
<td class="tg-c3ow">11.8ms</td> | |
</tr> | |
</tbody> | |
</table> | |
## 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{wang2023repvitsam, | |
title={RepViT-SAM: Towards Real-Time Segmenting Anything}, | |
author={Ao Wang and Hui Chen and Zijia Lin and Jungong Han and Guiguang Ding}, | |
year={2023}, | |
eprint={2312.05760}, | |
archivePrefix={arXiv}, | |
primaryClass={cs.CV} | |
} | |
``` | |