Instructions to use nrl-ai/samexporter-onnx-models with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sam2
How to use nrl-ai/samexporter-onnx-models with sam2:
# Use SAM2 with images import torch from sam2.sam2_image_predictor import SAM2ImagePredictor predictor = SAM2ImagePredictor.from_pretrained(nrl-ai/samexporter-onnx-models) with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): predictor.set_image(<your_image>) masks, _, _ = predictor.predict(<input_prompts>)# Use SAM2 with videos import torch from sam2.sam2_video_predictor import SAM2VideoPredictor predictor = SAM2VideoPredictor.from_pretrained(nrl-ai/samexporter-onnx-models) with torch.inference_mode(), torch.autocast("cuda", dtype=torch.bfloat16): state = predictor.init_state(<your_video>) # add new prompts and instantly get the output on the same frame frame_idx, object_ids, masks = predictor.add_new_points(state, <your_prompts>): # propagate the prompts to get masklets throughout the video for frame_idx, object_ids, masks in predictor.propagate_in_video(state): ... - Notebooks
- Google Colab
- Kaggle
SAMExporter validated ONNX models
Real, structurally checked ONNX artifacts for
samexporter. These files are
published by NRL.ai so the AnyLearning and SAMExporter documentation can use
stable, revisioned model links.
Available artifacts
| Directory | Prompt types | Source | Terms |
|---|---|---|---|
sam_vit_b/ |
point, rectangle | Meta SAM ViT-B | Apache-2.0 |
mobile_sam/ |
point, rectangle | MobileSAM TinyViT | Apache-2.0 |
efficient_sam_ti/ |
point, rectangle | EfficientSAM-Ti official ONNX | Apache-2.0 |
efficient_sam_s/ |
point, rectangle | EfficientSAM-S official ONNX | Apache-2.0 |
sam2_1_hiera_tiny/ |
point, rectangle, mask refinement | Meta SAM 2.1 Tiny | Apache-2.0 |
sam3/ |
text, positive/negative geometry | Meta SAM3 | SAM License (included) |
Each directory contains its applicable upstream license. This repository uses
license: other because SAM3 is distributed under Meta's SAM License while
the other five families are Apache-2.0. Use and redistribution remain subject
to the license in each directory. No source checkpoints or training datasets
are included.
Download
Download only the family you need:
hf download nrl-ai/samexporter-onnx-models \
--include "mobile_sam/*" \
--local-dir output_models
Or download every family:
hf download nrl-ai/samexporter-onnx-models --local-dir output_models
SAM3 uses ONNX external data: keep sam3_decoder.onnx and
sam3_decoder.onnx.data together in the same directory.
Validation
- Every ONNX graph passes
onnx.checker.check_model(path)with external data resolved from its published directory. - SAM ViT-B, MobileSAM, SAM 2.1 Tiny, and SAM3 were exported from real official checkpoints; EfficientSAM-Ti and EfficientSAM-S are the official upstream split ONNX pairs.
- Point and rectangle results were run with ONNX Runtime CPU on the landscape truck and portrait plant images in the SAMExporter repository.
- Full-resolution overlays and sibling resource logs are retained in
visual_results/.
Exact file digests are listed in CHECKSUMS.sha256. The export provenance is
listed in PROVENANCE.md.
Runtime
pip install "samexporter[runtime-cpu]"
python -m samexporter.inference \
--sam_variant sam \
--encoder_model output_models/mobile_sam/mobile_sam.encoder.onnx \
--decoder_model output_models/mobile_sam/mobile_sam.decoder.onnx \
--image image.jpg \
--prompt prompt.json \
--output result.png
See the
samexporter documentation
for family-specific conversion, provider, prompt, and performance guidance.