Export Meta AI's Segment Anything 3 (SAM3) model to ONNX, then build a TensorRT engine for real-time segmentation. This repo includes a CUDA inference library and demo apps for semantic and instance segmentation.
The numbers show end to end image processing latency per image (4K resolution) in ms excluding image load/save time.
| Hardware | HF+PyTorch | TensorRT+CUDA | Speedup | Notes |
|---|---|---|---|---|
| Jetson Orin NX | 6600 ms | 950 ms | 6.95x | Uses zero-copy |
| Jetson Thor | 1709.8 ms | 125.9 ms | 13.58x | R38.2.2, CUDA 13.0, TRT 10.13.3, MAXN, zero-copy, 10x 4K images |
| DGX Spark | Please contribute | |||
| RTX 3090 | 438 ms | 75 ms | 5.82x | |
| RTX 5090 | 120.9 ms | 24.8 ms | 4.88x | COCO val2017, TRT 10.14.1 |
| A10 | 545.3 ms | 161.1 | 3.38x | GPU hits 100% utilization |
| A100 | 314.1 ms | 48.8 ms | 6.43x | 40GB SXM4 variant |
| H100 | 265.3 ms | 34.6 ms | 7.66x | PCIe variant |
| H100 | 213.2 ms | 24.9 ms | 8.56x | SXM5 variant |
| GH200 | 142.3 ms | 23.3 ms | 6.11x | arm64+H100 iGPU, without zero-copy |
| GH200 | 142.3 ms | 26.4 ms | 5.39x | using zero-copy |
| B200 | 160.0 ms | 17.7 ms | 9.03x | SXM6 variant |
Note: the HF+PyTorch path is GPU-backed too, so these numbers compare two GPU implementations rather than CPU vs GPU.
Please contribute your results and I will be happy to add them here. Use this guide to run the benchmarks yourself.
Semantic segmentation produced by the C++ demo app (prompt='dog')
Instance segmentation results (prompt='box')
python/ - ONNX export and visualization scripts.cpp/ - C++/CUDA library and apps (TensorRT inference).docker/ - Container setup (Dockerfile.x86, with an aarch64 variant expected).demo/ - Example outputs from the C++ demo app.Request access to the gated model
HF_TOKEN has permission.HF_TOKEN as environment variable in the host. Docker will pick it up from there.Build the Docker container for your platform (all commands below run inside it)
docker build -t sam3-trt -f docker/Dockerfile.x86 .
For aarch64 platforms with shared CPU/GPU memory, the C++ library in this repo supports zero-copy inference paths.
Build and run the aarch64 container:
docker build -t sam3-trt-aarch64 -f docker/Dockerfile.aarch64 .
HF_TOKEN and run the docker containerexport HF_TOKEN=<YOUR TOKEN>
docker run -it --rm \
--network=host \
--gpus all \
--ipc=host \
--ulimit memlock=-1 \
--ulimit stack=67108864 \
--runtime=nvidia \
--env HF_TOKEN \
-v "$PWD":/workspace \
-w /workspace \
sam3-trt bash
python python/onnxexport.py
This produces onnx_weights/sam3_dynamic.onnx plus external weight shards.
trtexec --onnx=onnx_weights/sam3_dynamic.onnx --saveEngine=sam3_fp16.plan --fp16 --verbose
mkdir cpp/build && cd cpp/build
cmake ..
make
./sam3_pcs_app <image_dir> <engine_path.engine>
Results are written to a results/ folder.
This is a very raw project and provides the crucial backend TensorRT/CUDA bits necessary for anything. From here, please feel free to fan out into any application you like. Pull requests are very welcome! Here are some ideas I can think of:
HF_TOKEN has access to facebook/sam3.transformers from source if SAM3 is missing.onnx_weights/ directory is copied (external data is required).pkg-config.sam3_trt.sam3_pcs_app (semantic/instance visualization modes).SAM3_VISUALIZATION::VIS_NONE in your application, you need to apply sigmoid yourself.trtexec instead.Use the same image directory and prompt for all runs. Both paths time the model pipeline and exclude image load/save.
Huggingface + PyTorch:
python python/basic_script.py <image_dir>
TensorRT + CUDA (benchmark mode disables output writes):
./sam3_pcs_app <image_dir> <engine_path.engine> 1
device to cuda if desired).onnx_weights/ directory together.trtexec for quick engine builds and benchmarking.LICENSE).If this saved you time, drop a ⭐ so others can find it and ship SAM-3 faster.
All views expressed here are my own. This project is not affiliated with my employer.
Cuda
62.8%
Python
21.3%
C++
13.2%
CMake
2.8%
Export Meta AI's Segment Anything 3 (SAM3) model to ONNX, then build a TensorRT engine for real-time segmentation. This repo includes a CUDA inference library and demo apps for semantic and instance segmentation.
The numbers show end to end image processing latency per image (4K resolution) in ms excluding image load/save time.
| Hardware | HF+PyTorch | TensorRT+CUDA | Speedup | Notes |
|---|---|---|---|---|
| Jetson Orin NX | 6600 ms | 950 ms | 6.95x | Uses zero-copy |
| Jetson Thor | 1709.8 ms | 125.9 ms | 13.58x | R38.2.2, CUDA 13.0, TRT 10.13.3, MAXN, zero-copy, 10x 4K images |
| DGX Spark | Please contribute | |||
| RTX 3090 | 438 ms | 75 ms | 5.82x | |
| RTX 5090 | 120.9 ms | 24.8 ms | 4.88x | COCO val2017, TRT 10.14.1 |
| A10 | 545.3 ms | 161.1 | 3.38x | GPU hits 100% utilization |
| A100 | 314.1 ms | 48.8 ms | 6.43x | 40GB SXM4 variant |
| H100 | 265.3 ms | 34.6 ms | 7.66x | PCIe variant |
| H100 | 213.2 ms | 24.9 ms | 8.56x | SXM5 variant |
| GH200 | 142.3 ms | 23.3 ms | 6.11x | arm64+H100 iGPU, without zero-copy |
| GH200 | 142.3 ms | 26.4 ms | 5.39x | using zero-copy |
| B200 | 160.0 ms | 17.7 ms | 9.03x | SXM6 variant |
Note: the HF+PyTorch path is GPU-backed too, so these numbers compare two GPU implementations rather than CPU vs GPU.
Please contribute your results and I will be happy to add them here. Use this guide to run the benchmarks yourself.
Semantic segmentation produced by the C++ demo app (prompt='dog')
Instance segmentation results (prompt='box')
python/ - ONNX export and visualization scripts.cpp/ - C++/CUDA library and apps (TensorRT inference).docker/ - Container setup (Dockerfile.x86, with an aarch64 variant expected).demo/ - Example outputs from the C++ demo app.Request access to the gated model
HF_TOKEN has permission.HF_TOKEN as environment variable in the host. Docker will pick it up from there.Build the Docker container for your platform (all commands below run inside it)
docker build -t sam3-trt -f docker/Dockerfile.x86 .
For aarch64 platforms with shared CPU/GPU memory, the C++ library in this repo supports zero-copy inference paths.
Build and run the aarch64 container:
docker build -t sam3-trt-aarch64 -f docker/Dockerfile.aarch64 .
HF_TOKEN and run the docker containerexport HF_TOKEN=<YOUR TOKEN>
docker run -it --rm \
--network=host \
--gpus all \
--ipc=host \
--ulimit memlock=-1 \
--ulimit stack=67108864 \
--runtime=nvidia \
--env HF_TOKEN \
-v "$PWD":/workspace \
-w /workspace \
sam3-trt bash
python python/onnxexport.py
This produces onnx_weights/sam3_dynamic.onnx plus external weight shards.
trtexec --onnx=onnx_weights/sam3_dynamic.onnx --saveEngine=sam3_fp16.plan --fp16 --verbose
mkdir cpp/build && cd cpp/build
cmake ..
make
./sam3_pcs_app <image_dir> <engine_path.engine>
Results are written to a results/ folder.
This is a very raw project and provides the crucial backend TensorRT/CUDA bits necessary for anything. From here, please feel free to fan out into any application you like. Pull requests are very welcome! Here are some ideas I can think of:
HF_TOKEN has access to facebook/sam3.transformers from source if SAM3 is missing.onnx_weights/ directory is copied (external data is required).pkg-config.sam3_trt.sam3_pcs_app (semantic/instance visualization modes).SAM3_VISUALIZATION::VIS_NONE in your application, you need to apply sigmoid yourself.trtexec instead.Use the same image directory and prompt for all runs. Both paths time the model pipeline and exclude image load/save.
Huggingface + PyTorch:
python python/basic_script.py <image_dir>
TensorRT + CUDA (benchmark mode disables output writes):
./sam3_pcs_app <image_dir> <engine_path.engine> 1
device to cuda if desired).onnx_weights/ directory together.trtexec for quick engine builds and benchmarking.LICENSE).If this saved you time, drop a ⭐ so others can find it and ship SAM-3 faster.
All views expressed here are my own. This project is not affiliated with my employer.
Cuda
62.8%
Python
21.3%
C++
13.2%
CMake
2.8%