Official PyTorch implementation of RepViT-SAM, from the following paper:
RepViT-SAM: Towards Real-Time Segmenting Anything.
Ao Wang, Hui Chen, Zijia Lin, Jungong Han, and Guiguang Ding
[arXiv
]
Models are deployed on iPhone 12 with Core ML Tools to get latency.
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 nearlypip install -e .
# download pretrained checkpoint
mkdir weights && cd weights
wget https://github.com/THU-MIG/RepViT/releases/download/v1.0/repvit_sam.pt
Our Hugging Face demo is here
python app/app.py
Please refer to coreml_example.ipynb
Comparison between RepViT-SAM and others in terms of latency. The latency (ms) is measured with the standard resolution of 1024
Platform | Image encoder | Mask decoder | ||
---|---|---|---|---|
RepViT-SAM | MobileSAM | ViT-B-SAM | ||
iPhone | 48.9ms | OOM | OOM | 11.6ms |
Macbook | 44.8ms | 482.2ms | 6249.5ms | 11.8ms |
Comparison results on BSDS500.
Model | zero-shot edge detection | ||
---|---|---|---|
ODS | OIS | AP | |
ViT-H-SAM | .768 | .786 | .794 |
ViT-B-SAM | .743 | .764 | .726 |
MobileSAM | .756 | .768 | .746 |
RepViT-SAM | .764 | .786 | .773 |
Comparison results on COCO and SegInW.
Model | zero-shot instance segmentation | SegInW | |||
---|---|---|---|---|---|
AP | Mean AP | ||||
ViT-H-SAM | 46.8 | 31.8 | 51.0 | 63.6 | 48.7 |
ViT-B-SAM | 42.5 | 29.8 | 47.0 | 56.8 | 44.8 |
MobileSAM | 42.7 | 27.0 | 46.5 | 61.1 | 43.9 |
RepViT-SAM | 44.4 | 29.1 | 48.6 | 61.4 | 46.1 |
Comparison results on DAVIS 2017 and UVO.
Model | z.s. VOS | z.s. VIS | ||
---|---|---|---|---|
AR100 | ||||
ViT-H-SAM | 77.4 | 74.6 | 80.2 | 28.8 |
ViT-B-SAM | 71.3 | 68.5 | 74.1 | 19.1 |
MobileSAM | 71.1 | 68.6 | 73.6 | 22.7 |
RepViT-SAM | 73.5 | 71.0 | 76.1 | 25.3 |
Comparison results on DUTS.
Comparison results on MVTec.
Model | z.s. s.o.s. | z.s. a.d. |
---|---|---|
|
||
ViT-H-SAM | 0.046 | 37.65 |
ViT-B-SAM | 0.121 | 36.62 |
MobileSAM | 0.147 | 36.44 |
RepViT-SAM | 0.066 | 37.96 |
The code base is partly built with SAM and MobileSAM.
Thanks for the great implementations!
If our code or models help your work, please cite our paper:
@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}
}