Prerequisites
- Python 3.9 or later
- CUDA 11.8 or later (for GPU training)
- 16GB+ VRAM per GPU
- Linux operating system (recommended)
Installation
Install SAM 3
First, install the SAM 3 package from source:This installs SAM 3 in editable mode with all core dependencies.
Install Training Dependencies
Install additional packages required for training:Optional dependencies:
Verify PyTorch Installation
Ensure PyTorch is installed with CUDA support:Expected output:If CUDA is not available, reinstall PyTorch:
Directory Structure
Set up your training workspace:Prepare Your Dataset
Format Annotations
Ensure your dataset uses COCO JSON format:The annotations file should contain:
images: List of image metadataannotations: Bounding boxes and optional maskscategories: Object categories
Environment Configuration
Set Environment Variables
Create a.env file or export variables:
Configure Paths
Update your training config with local paths:GPU Setup
Single GPU
For single GPU training:Multiple GPUs (Single Node)
For multi-GPU training on one machine:Cluster Setup
For SLURM cluster training, see Cluster Training.Verify Installation
Test that everything is set up correctly:Troubleshooting
CUDA Out of Memory
If you encounter OOM errors:-
Reduce batch size in config:
-
Reduce image resolution:
-
Enable gradient accumulation:
Import Errors
If modules are not found:Slow Data Loading
If data loading is slow:Next Steps
Now that your environment is set up:Configuration
Learn about training configuration options
Local Training
Start training on local GPUs