Real-time video segmentation on NVIDIA Jetson using SAM3 + TensorRT + DeepStream.
SAM3-Edge brings Meta's Segment Anything Model 3 (SAM3) to edge devices, specifically optimized for NVIDIA Jetson AGX Orin. It provides:
- TensorRT Acceleration: ViT encoder and mask decoder exported to TensorRT FP16 engines
- DeepStream Integration: GStreamer pipeline with nvinfer plugin for hardware-accelerated video processing
- FastAPI Server: REST API for inference on images and video streams
- CUDA Streams: Async pipelined inference to minimize latency
- Text Prompts: Segment objects by description ("red car", "person") using SAM3's native VETextEncoder
- SQLite Storage: Persistent detection storage for video processing
sam3-edge/
├── sam3/ # SAM3 model (local submodule)
│ └── sam3/model/trt_export.py # TensorRT export wrapper
├── sam3_deepstream/ # Main package
│ ├── api/ # FastAPI REST server
│ ├── export/ # TensorRT export utilities
│ ├── inference/ # Runtime inference engines
│ └── deepstream/ # DeepStream pipeline configs
├── install_jetson.sh # One-shot Jetson installation script
└── pyproject.toml # UV workspace config
Dependencies:
sam3/- SAM3 model with TensorRT export support (local directory)
- NVIDIA Jetson AGX Orin with JetPack 6.x (R36.4+)
- Docker with NVIDIA Container Toolkit
- PyTorch with CUDA from NVIDIA's Jetson wheel server
# Clone with Git LFS (required for TensorRT engines)
git lfs install
git clone https://github.com/oldhero5/sam3-edge.git
cd sam3-edge
git lfs pull
# Place SAM3 checkpoint in expected location
mkdir -p sam3/checkpoints
cp /path/to/sam3.pt sam3/checkpoints/
# Run full installation (builds Docker, exports TensorRT engines)
./install_jetson.shThe installation script:
- Installs system dependencies and UV package manager
- Builds the Docker image with all dependencies
- Exports TensorRT engines inside Docker (ensures TRT version compatibility)
- Prepares database directories
cd sam3_deepstream
docker compose -f docker-compose.jetson.yml up -d
# Check health
curl http://localhost:8000/health# Health check
curl http://localhost:8000/health
# Text-based segmentation (returns JSON with RLE masks, saves PNG to outputs/)
curl -X POST http://localhost:8000/api/v1/segment \
-F "[email protected]" \
-F "text_prompt=car"
# Point-based segmentation
curl -X POST http://localhost:8000/segment \
-F "[email protected]" \
-F "points=0.5,0.5,1"Environment variables:
| Variable | Default | Description |
|---|---|---|
SAM3_USE_TRT |
0 | Enable TensorRT acceleration |
SAM3_ENGINE_DIR |
./engines | Directory containing TRT engines |
SAM3_OUTPUT_DIR |
./outputs | Directory for saved results |
SAM3_USE_PE_BACKBONE |
0 | Enable Perception Encoder backbone |
SAM3_CHECKPOINT |
- | Path to SAM3 checkpoint |
API_HOST |
0.0.0.0 | API server host |
API_PORT |
8000 | API server port |
On Jetson AGX Orin (64GB):
| Component | Precision | Latency |
|---|---|---|
| ViT Encoder | FP16 | ~35ms |
| Mask Decoder | FP16 | ~8ms |
| End-to-end | FP16 | ~50ms |
With keyframe optimization (reusing embeddings):
- Keyframe: ~50ms
- Non-keyframe: ~8ms (decoder only)
# Run tests (Docker with GPU)
make test
# Build Docker image
make build
# Export TensorRT engines
make exportFor complete Jetson AGX Orin setup, use the installation script:
# Full installation (system deps, Docker, TRT export, database)
./install_jetson.sh
# With explicit checkpoint path
./install_jetson.sh --checkpoint /path/to/sam3_checkpoint.pt
# Docker image only (no TRT export)
./install_jetson.sh --docker-only
# Skip Docker rebuild (use existing image)
./install_jetson.sh --skip-docker
# Health check
./install_jetson.sh --health-checkTensorRT engines are platform-specific and must be built with the same TensorRT version used at runtime. The installation script handles this automatically by:
- Building the Docker image first
- Running TensorRT export inside the Docker container
- Mounting the output directory so engines are accessible on host
This ensures the engines work correctly regardless of host vs container TensorRT version differences.
| Option | Description |
|---|---|
--checkpoint <path> |
Export TensorRT engines from checkpoint |
--docker-only |
Only build Docker image |
--skip-docker |
Skip Docker image build |
--init-db |
Initialize database only |
--health-check |
Run system health checks |
--precision <fp16|fp32|int8> |
TensorRT precision (default: fp16) |
--push |
Push image to DockerHub |
--repo <user/repo> |
DockerHub repository name |
# Pull Jetson image
docker pull sam3edge/sam3-edge:jetson-latest
# Run with docker-compose
cd sam3_deepstream
docker compose -f docker-compose.jetson.yml up -d# Build and push to your DockerHub account
./install_jetson.sh --push --repo yourusername/sam3-edge
# Or manually:
docker login
docker tag sam3-edge:jetson yourusername/sam3-edge:jetson-latest
docker push yourusername/sam3-edge:jetson-latestSAM3-Edge is designed for future multi-device federation where many Jetson devices process video at the edge and sync detections to a central server.
Current design supports:
device_idtracking in all database tables- Export endpoint for syncing detections
Future features (planned):
- Automatic sync to central aggregation server
- Distributed query across device network
MIT License - see LICENSE file.
- Meta AI SAM3 - Original SAM3 implementation
- NVIDIA DeepStream - Video analytics SDK