ONNX export and inference for SAM3.
git clone https://github.com/wkentaro/sam3-onnx.git --recursive && cd sam3-onnx
uvx hf download wkentaro/sam3-onnx-models --local-dir models # download pre-exported models
uv run --no-dev infer_onnx.py --image images/bus.jpg --text-prompt person
uv run --no-dev infer_onnx.py --image images/sofa.jpg --text-prompt sofa
uv run --no-dev infer_onnx.py --image images/dog.jpg --box-prompt # opens a gui to select boxgit clone https://github.com/wkentaro/sam3-onnx.git --recursive && cd sam3-onnx
uv sync # dev mode for exporting onnx unlike --no-devInference with pytorch
# with text prompt
uv run infer_torch.py --image images/bus.jpg --text-prompt person
# with box prompt
uv run infer_torch.py --image images/bus.jpg --box-prompt 0.548,0.658,0.043,0.095
uv run infer_torch.py --image images/bus.jpg --box-prompt # opens a gui to select boxExport to onnx
# create models/*.onnx
uv run export_onnx.py
# upload to Hugging Face Hub
# uvx hf upload wkentaro/sam3-onnx-models models/ --include '*.onnx*'Inference with onnx
# with text prompt
uv run infer_onnx.py --image images/bus.jpg --text-prompt person
# with box prompt
uv run infer_torch.py --image images/bus.jpg --box-prompt 0.548,0.658,0.043,0.095
uv run infer_torch.py --image images/bus.jpg --box-prompt # opens a gui to select boxIf don't want to export yourself, download them from the Hugging Face repo:
models
├── sam3_decoder.onnx
├── sam3_decoder.onnx.data
├── sam3_image_encoder.onnx
├── sam3_image_encoder.onnx.data
├── sam3_language_encoder.onnx
└── sam3_language_encoder.onnx.data
uv run infer_onnx.py --image images/bus.jpg --text-prompt person
uv run infer_onnx.py --image images/bus.jpg --text-prompt window
uv run infer_onnx.py --image images/bus.jpg --box-prompt 0.547,0.656,0.042,0.091 # select a blockuv run infer_onnx.py --image images/sofa.jpg --text-prompt person
uv run infer_onnx.py --image images/sofa.jpg --text-prompt sofauv run infer_onnx.py --image images/dog.jpg --text-prompt dog
uv run infer_onnx.py --image images/dog.jpg --text-prompt ground
uv run infer_onnx.py --image images/dog.jpg --box-prompt 0.561,0.342,0.167,0.217