Abstract
The Segment Anything Model (SAM) has revolutionized computer vision with its universal segmentation capabilities. However, its reliance on heavy Vision Transformer (ViT) encoders limits its deployment on mobile and edge devices. This paper introduces RepViT-SAM, a high-efficiency model that replaces the ViT encoder with a RepViT architecture. By utilizing decoupled distillation and structural reparameterization, RepViT-SAM achieves a 10x speedup over existing lightweight models like MobileSAM, enabling real-time inference on mobile hardware (48.9ms on iPhone 12) while maintaining superior zero-shot performance.
1. Introduction
The original SAM architecture, while powerful, is computationally prohibitive for real-time mobile applications due to the massive ViT-H image encoder. Previous attempts to optimize SAM, such as MobileSAM (which uses TinyViT), still face significant memory and latency bottlenecks on mobile hardware. In practice, MobileSAM often triggers "Out of Memory" (OOM) errors on devices like the iPhone 12. The core challenge is finding an architecture that offers the speed of a Convolutional Neural Network (CNN) with the powerful representational capabilities of a Transformer.
2. Methodology
RepViT-SAM addresses these efficiency gaps through three primary technical innovations:
- RepViT Backbone: The model adopts the RepViT architecture, which revisits CNN designs through a ViT lens. It employs structural reparameterization to fuse multiple branches into a single efficient path during inference, minimizing memory overhead.
- Decoupled Distillation: To preserve the zero-shot capabilities of the original SAM, the researchers employed a teacher-student distillation strategy. Knowledge was transferred from the ViT-H encoder to the RepViT encoder using Mean Squared Error (MSE) loss on image embeddings, avoiding the need for full end-to-end retraining.
- Resolution Alignment: The final downsampling layer of the RepViT encoder was adjusted to a stride of 1. This ensures the output spatial resolution matches the expectations of the original SAM mask decoder, allowing for seamless integration.
3. Results and Discussion
RepViT-SAM was evaluated across several benchmarks, including COCO, BSDS500, and DAVIS 2017.
3.1 Performance and Efficiency
On an iPhone 12, RepViT-SAM achieves an inference time of 48.9ms. In contrast, MobileSAM failed to execute on the same device due to memory limits. On a Macbook M1 Pro, RepViT-SAM demonstrated a nearly 10x speed advantage over MobileSAM (44.8ms vs 482.2ms).
3.2 Accuracy and Zero-Shot Capability
Despite the significant reduction in latency, RepViT-SAM maintains high accuracy. It achieved 44.4 AP on the COCO instance segmentation task, outperforming MobileSAM (42.7 AP) and even the larger ViT-B-SAM. In edge detection tasks (BSDS500), it reached an ODS of .764, closely approaching the .768 ODS of the original ViT-H-SAM, proving that the distillation process successfully captured the teacher's knowledge.
4. Limitations and Future Work
While the decoupled distillation strategy is highly effective for macro-level visual features, the authors note it can sometimes fall short on extremely fine-grained features compared to the original massive ViT-H model. Future work will involve exploring more aggressive quantization and applying this RepViT-based approach to complex, multi-frame video segmentation tasks where real-time performance is critical.
5. Conclusion
RepViT-SAM demonstrates that well-optimized CNN-based architectures can significantly outperform Transformer-based models in mobile deployment scenarios. By decoupling the encoder and utilizing efficient distillation, the "Segment Anything" capability is brought to edge devices in real-time, bridging the gap between high-end research and practical mobile applications.
Summary updated