CLI wrapper for Segment Anything Model (SAM), optimized for cross-platform deployment using ONNX Runtime.
- Cross-platform GPU acceleration: CUDA (NVIDIA), DirectML (AMD/Intel on Windows), CoreML (Apple Silicon)
- Small binary size: ~50-100MB (vs ~5GB with PyTorch)
- Multiple prompt types: Box, point, and automatic segmentation
- Multiple model variants: MobileSAM for speed, SAM ViT-B/L/H for quality
Download the pre-built binary for your platform from the Releases page:
| Platform | Binary | GPU Support |
|---|---|---|
| Windows | leaxer-sam-x86_64-pc-windows-msvc.exe |
CUDA, DirectML |
| Linux | leaxer-sam-x86_64-unknown-linux-gnu |
CUDA |
| macOS (Apple Silicon) | leaxer-sam-aarch64-apple-darwin |
CoreML |
| macOS (Intel) | leaxer-sam-x86_64-apple-darwin |
CPU |
leaxer-sam segment \
--image photo.jpg \
--boxes "[[100,50,300,280],[500,400,620,550]]" \
--output masks/ \
--json result.jsonleaxer-sam segment \
--image photo.jpg \
--points "[[200,150],[550,450]]" \
--labels "[1,1]" \
--output masks/ \
--json result.jsonleaxer-sam auto \
--image photo.jpg \
--points-per-side 32 \
--min-area 100 \
--output masks/ \
--json result.json| Argument | Required | Default | Description |
|---|---|---|---|
--image |
Yes | - | Path to input image |
--boxes |
No | - | Bounding boxes as JSON array [[x1,y1,x2,y2],...] |
--points |
No | - | Point prompts as JSON array [[x,y],...] |
--labels |
No | - | Point labels (1=foreground, 0=background) |
--model |
No | mobile_sam | Model variant |
--output |
Yes | - | Output directory for mask PNG files |
--json |
Yes | - | Output JSON path for metadata |
--points-per-side |
No | 32 | Grid density for auto mode |
--min-area |
No | 100 | Minimum mask area for auto mode |
{
"image_size": [1920, 1080],
"segments": [
{
"id": 0,
"bbox": [100, 50, 300, 280],
"confidence": 0.98,
"mask_path": "masks/mask_0.png"
},
{
"id": 1,
"bbox": [500, 400, 620, 550],
"confidence": 0.95,
"mask_path": "masks/mask_1.png"
}
]
}Models are downloaded separately by the Leaxer app and stored in:
- Windows/macOS:
~/Documents/Leaxer/models/sam/ - Linux:
~/.local/share/Leaxer/models/sam/
| Model | Encoder | Decoder | Description |
|---|---|---|---|
mobile_sam |
~40MB | ~15MB | Fast, lightweight |
sam_vit_b |
~350MB | ~15MB | Good balance |
sam_vit_l |
~1.1GB | ~15MB | High quality |
sam_vit_h |
~2.3GB | ~15MB | Highest quality |
ONNX Runtime automatically selects the best available execution provider:
| Platform | GPU Provider | Supported GPUs |
|---|---|---|
| Windows | CUDAExecutionProvider | NVIDIA |
| Windows | DirectMLExecutionProvider | NVIDIA, AMD, Intel |
| Linux | CUDAExecutionProvider | NVIDIA |
| macOS | CoreMLExecutionProvider | Apple Silicon (M1/M2/M3) |
| All | CPUExecutionProvider | Fallback |
- Python 3.10+
- PyInstaller
# Install dependencies (choose one)
pip install -r requirements/cuda.txt # NVIDIA GPU
pip install -r requirements/cpu.txt # CPU only
pip install pyinstaller
# Build
pyinstaller pyinstaller/leaxer-sam.spec --distpath distTo convert PyTorch models to ONNX:
pip install -r requirements/convert.txt
python convert/export_onnx.py --model mobile_sam --output models/
python convert/export_onnx.py --model sam_vit_b --output models/MIT License - see LICENSE for details.
This project wraps Segment Anything Model by Meta AI (Apache-2.0 License) and MobileSAM.