vietanhdev/samexporter

Export and run SAM, MobileSAM, EfficientSAM, SAM 2/2.1, and SAM 3 as ONNX for portable image segmentation

What it solves

SAMExporter provides a way to export and run various Segment Anything Model (SAM) variants in the ONNX Runtime. This allows these complex vision models to be deployed more portably and efficiently across different hardware accelerators without needing the original PyTorch environment.

How it works

The tool converts PyTorch checkpoints from multiple SAM families—including the original SAM, MobileSAM, EfficientSAM, SAM 2, and SAM 3—into ONNX format. It typically splits the models into separate image encoders and decoders to optimize performance. For SAM 3, it also exports a language encoder to support text-driven segmentation. Once exported, the models can be run using a provided inference script that supports various prompt types (points, rectangles, and text) and integrates with numerous ONNX Runtime execution providers (such as TensorRT, OpenVINO, and CUDA).

Who it’s for

It is designed for developers and researchers who need to deploy SAM models into production environments, particularly those targeting CPU-only devices or specialized AI accelerators where PyTorch is not ideal.

Highlights

  • Broad Model Support: Compatible with SAM (ViT-B/L/H), MobileSAM, EfficientSAM, SAM 2/2.1, and SAM 3.
  • Multi-Modal Prompting: Supports point and rectangle prompts across all models, with SAM 3 adding open-vocabulary text-driven segmentation.
  • Hardware Flexibility: Integrates with a wide array of ONNX Runtime backends including TensorRT, OpenVINO, DirectML, and CoreML.
  • Deployment Optimization: Offers quantization options to reduce model size and memory usage, and supports caching image embeddings for interactive applications.

Related

  • Project
  • Project
  • Project
  • Project