Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,6 @@ Thumbs.db
# BPE vocabulary files
*.bpe
*.vocab

# Package manager lock files
uv.lock
70 changes: 54 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,42 +57,80 @@ This breakthrough is driven by an innovative data engine that has automatically

## Installation

### Prerequisites
### Quick Install (Recommended)

- Python 3.12 or higher
The install script automatically detects your platform (x86 or Jetson) and configures everything:

```bash
git clone https://github.com/facebookresearch/sam3.git
cd sam3
./install.sh
```

The script will:
- Detect x86 or Jetson hardware automatically
- Use the appropriate Python version (3.12 for x86, 3.10 for Jetson)
- Install PyTorch from the correct source
- Install SAM3 with notebook dependencies

**Install options:**
```bash
./install.sh # Default: includes notebook dependencies
./install.sh --minimal # Base package only
./install.sh --dev # Development dependencies
./install.sh --all # All optional dependencies
```

### Manual Installation

#### Prerequisites

- Python 3.9 or higher (3.12 recommended for x86, 3.10 required for Jetson)
- PyTorch 2.7 or higher
- CUDA-compatible GPU with CUDA 12.6 or higher

1. **Create a new Conda environment:**
#### x86 Platforms

```bash
# Create environment
conda create -n sam3 python=3.12
conda deactivate
conda activate sam3
```

2. **Install PyTorch with CUDA support:**

```bash
# Install PyTorch
pip install torch==2.7.0 torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126

# Clone and install
git clone https://github.com/facebookresearch/sam3.git
cd sam3
pip install -e ".[notebooks]"
```

3. **Clone the repository and install the package:**
#### NVIDIA Jetson Platforms

For Jetson AGX Orin, Orin Nano, and other devices running JetPack 6.x:

```bash
# Create environment (Python 3.10 required for NVIDIA PyTorch)
python3.10 -m venv sam3_env
source sam3_env/bin/activate

# Install PyTorch from NVIDIA Jetson AI Lab
pip install torch==2.8.0 torchvision==0.23.0 --index-url=https://pypi.jetson-ai-lab.io/jp6/cu126

# Clone and install with Jetson extras
git clone https://github.com/facebookresearch/sam3.git
cd sam3
pip install -e .
pip install -e ".[jetson,notebooks]"
```

4. **Install additional dependencies for example notebooks or development:**
See the [Jetson Setup Guide](docs/JETSON_SETUP.md) for detailed instructions and troubleshooting.

```bash
# For running example notebooks
pip install -e ".[notebooks]"
#### Optional Dependencies

# For development
pip install -e ".[train,dev]"
```bash
pip install -e ".[notebooks]" # Jupyter notebooks and visualization
pip install -e ".[train,dev]" # Training and development tools
pip install -e ".[jetson]" # Jetson-specific tools (jtop monitoring)
```

## Getting Started
Expand Down
193 changes: 193 additions & 0 deletions docs/JETSON_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# SAM 3 Installation Guide for NVIDIA Jetson Platforms

This guide provides detailed instructions for installing and running SAM 3 on NVIDIA Jetson devices, including AGX Orin, Orin Nano, and Orin NX running JetPack 6.x.

## Prerequisites

### Hardware Requirements
- **NVIDIA Jetson Device**: AGX Orin, Orin Nano, or Orin NX
- **JetPack**: 6.0 or later (tested on JetPack 6.2 / L4T R36.4)
- **Storage**: At least 10GB free space for model checkpoints
- **Memory**: 8GB+ RAM recommended for optimal performance

### Software Requirements
- **Python**: 3.10 (compatible with NVIDIA PyTorch builds for JetPack 6.x)
- **CUDA**: 12.6 or higher (included in JetPack 6.x)
- **PyTorch**: 2.8.0 or higher (from NVIDIA Jetson AI Lab)

## Installation Steps

### 1. Verify JetPack Version

```bash
cat /etc/nv_tegra_release
# Should show: R36.x.x (JetPack 6.x)
```

### 2. Create Virtual Environment

```bash
# Install venv if not available
sudo apt install python3.10-venv

# Create and activate virtual environment
python3 -m venv sam3_env
source sam3_env/bin/activate
pip install --upgrade pip
```

### 3. Install PyTorch for Jetson

Install PyTorch 2.8.0 from NVIDIA's Jetson AI Lab repository:

```bash
pip install torch==2.8.0 torchvision==0.23.0 --index-url=https://pypi.jetson-ai-lab.io/jp6/cu126
```

Verify installation:
```bash
python -c "import torch; print(f'PyTorch: {torch.__version__}'); print(f'CUDA available: {torch.cuda.is_available()}')"
```

### 4. Install SAM 3

Clone and install SAM 3:

```bash
git clone https://github.com/facebookresearch/sam3.git
cd sam3
pip install -e ".[notebooks]" # Include notebook dependencies
```

### 5. Request Model Access

SAM 3 requires accessing gated model weights:

1. Visit https://huggingface.co/facebook/sam3
2. Click "Request access" and accept terms
3. Wait for Meta approval (usually within 1-2 days)

### 6. Download Model Checkpoints

After approval:

```bash
pip install huggingface-hub
huggingface-cli login # Enter your Hugging Face token

# Download checkpoints
huggingface-cli download facebook/sam3 --local-dir ./checkpoints
```

## Performance Optimization

### Enable Maximum Performance Mode

```bash
# Enable all CPU cores at maximum frequency
sudo jetson_clocks

# Set to maximum performance mode (MODE 0)
sudo nvpmodel -m 0
```

### Verify Performance Settings

```bash
# Check current power mode
sudo nvpmodel -q

# Monitor system performance
jtop # Install with: sudo pip install jetson-stats
```

## Usage Examples

### Basic Import Test

```python
import torch
from sam3 import build_sam3_image_model

# Verify CUDA
print(f"PyTorch: {torch.__version__}")
print(f"CUDA available: {torch.cuda.is_available()}")
print(f"GPU: {torch.cuda.get_device_name(0)}")
```

### Image Segmentation

See the example notebooks in `examples/` directory:
- `sam3_image_predictor_example.ipynb` - Image segmentation
- `sam3_video_predictor_example.ipynb` - Video segmentation

### Using FP16 for Faster Inference

```python
# Enable half precision (FP16) for ~2x speedup
model = model.half()
```

## Performance Expectations

Tested on **NVIDIA Jetson AGX Orin Developer Kit** (JetPack 6.2):

- **Image Segmentation**: ~100-300ms per frame (640x640, FP32)
- **With FP16**: ~50-150ms per frame
- **Memory Usage**: ~2-4GB VRAM
- **Model Size**: 848M parameters

### Optimization Tips

1. **Use FP16**: Reduces memory and increases speed
2. **Lower Resolution**: Process at 480x480 instead of 640x640
3. **Batch Processing**: Process multiple frames together when possible
4. **Frame Skipping**: For real-time video, process every 2nd or 3rd frame

## Troubleshooting

### Issue: CUDA Out of Memory

**Solution**: Enable FP16 or reduce batch size
```python
model = model.half() # Use FP16
```

### Issue: Slow Performance

**Solution**: Ensure jetson_clocks is enabled and nvpmodel is set to max performance
```bash
sudo jetson_clocks
sudo nvpmodel -m 0
```

### Issue: Import Errors

**Solution**: Ensure all dependencies are installed
```bash
pip install -e ".[notebooks]"
```

## Known Limitations

- **Python 3.10 Only**: NVIDIA PyTorch 2.8.0 for Jetson only supports Python 3.10
- **No TensorRT Optimization**: TensorRT acceleration not yet implemented (future enhancement)
- **Video Processing**: Real-time processing requires frame skipping or lower resolution

## Supported Platforms

- ✅ Jetson AGX Orin (tested)
- ✅ Jetson Orin Nano (should work, not extensively tested)
- ✅ Jetson Orin NX (should work, not extensively tested)
- ❌ Jetson Nano / TX2 / Xavier (JetPack 6.x not available)

## Getting Help

- **GitHub Issues**: https://github.com/facebookresearch/sam3/issues
- **Jetson Forums**: https://forums.developer.nvidia.com/c/agx-autonomous-machines/jetson-embedded-systems

## References

- [NVIDIA Jetson Documentation](https://developer.nvidia.com/embedded/jetson-orin)
- [PyTorch for Jetson](https://docs.nvidia.com/deeplearning/frameworks/install-pytorch-jetson-platform/)
- [SAM 3 Paper](https://ai.meta.com/research/publications/sam-3-segment-anything-with-concepts/)
Loading