train() call or take full control with the Custom Training API built on PyTorch Lightning.
Training paths
| Path | When to use |
|---|---|
RFDETR.train() (this page) | Quickstart, fine-tuning with standard options, Colab notebooks. One call sets up and runs everything. |
| Custom Training API | Custom callbacks, alternative loggers, multi-GPU strategies, integration with external frameworks, or any other customisation of the training loop. |
RFDETR.train() constructs RFDETRModelModule, RFDETRDataModule, and a Trainer internally.
Quick start
RF-DETR supports training on datasets in COCO and YOLO formats. The format is automatically detected based on the structure of your dataset directory.- Object detection
- Image segmentation
Effective batch size
The effective batch size determines how many samples the optimizer sees per update:batch_size and grad_accum_steps to maintain a total effective batch size of 16. For example:
| GPU | VRAM | batch_size | grad_accum_steps |
|---|---|---|---|
| A100 | 40–80 GB | 16 | 1 |
| RTX 4090 | 24 GB | 8 | 2 |
| RTX 3090 | 24 GB | 8 | 2 |
| T4 | 16 GB | 4 | 4 |
| RTX 3070 | 8 GB | 2 | 8 |
Result checkpoints
During training, multiple model checkpoints are saved to the output directory:| File | Description |
|---|---|
checkpoint.pth | Most recent checkpoint, saved at the end of the latest epoch. Use this to resume training. |
checkpoint_<N>.pth | Periodic checkpoint saved every N epochs (default is every 10). |
checkpoint_best_ema.pth | Best checkpoint based on validation score using EMA (Exponential Moving Average) weights. |
checkpoint_best_regular.pth | Best checkpoint based on validation score using raw (non-EMA) model weights. |
checkpoint_best_total.pth | Final checkpoint selected for inference. Contains only model weights and is chosen as the better of EMA and non-EMA models. |
Training checkpoints (
checkpoint.pth, checkpoint_<N>.pth) include model weights, optimizer state, scheduler state, and training metadata — use these to resume training.Evaluation checkpoints (checkpoint_best_ema.pth, checkpoint_best_regular.pth) store only model weights and are used to track the best-performing models.Stripped checkpoint (checkpoint_best_total.pth) contains only the final model weights and is optimized for inference and deployment.Load and run a fine-tuned model
After training completes, load your checkpoint by passing its path topretrain_weights:
- Object detection
- Image segmentation
Next steps
Dataset formats
Prepare your dataset in COCO or YOLO format for RF-DETR training.
Training parameters
Complete reference for all RF-DETR training configuration options.
Advanced training
Resume training, early stopping, multi-GPU, and memory optimization.
Training loggers
Track experiments with TensorBoard, W&B, MLflow, and ClearML.