donkey train command trains a neural network model using data collected from manual driving sessions. The trained model can then be used for autonomous driving.
Usage
Options
Path(s) to tub directories containing training data. Multiple tubs can be specified:
Output path and filename for the trained model. Example:
./models/pilot.h5If not specified, a default name will be generated based on the model type and timestamp.Model architecture type to use for training. Common types:
linear: Simple linear model (fastest, least accurate)categorical: Categorical output modelinferred: Model with inferred steeringlatent: Latent space model
DEFAULT_MODEL_TYPE from config.Location of the config file to use. Default is
./config.py in the current directory.Location of your custom config overrides file. Default is
./myconfig.py.AI framework to use for training:
tensorflow: TensorFlow/Keras (default)pytorch: PyTorch
DEFAULT_AI_FRAMEWORK from config.Path to a checkpoint file to resume training from (PyTorch only).
Path to a pre-trained model to use as a starting point (transfer learning). The model will start with these weights and fine-tune on your data.
Comment to add to the model database for tracking purposes. Use double quotes for multiple words:
Training Process
The training process:- Loads data from specified tub(s)
- Preprocesses images and normalizes inputs
- Splits data into training and validation sets
- Trains the model using the specified architecture
- Saves the trained model to the output path
- Records training history in the model database
Examples
Basic training with one tub
Train with multiple tubs
Train with specific model type
Use PyTorch instead of TensorFlow
Resume training from checkpoint (PyTorch)
Transfer learning from existing model
Add a comment for tracking
Use custom config file
Training Output Example
Configuration Options
Key configuration parameters inconfig.py / myconfig.py:
Model Types
Linear Model
Simple fully-connected network. Fast training, good for simple tracks.Categorical Model
Outputs discrete steering categories instead of continuous values.Custom Models
You can define custom model architectures in your config file.Transfer Learning
Transfer learning allows you to start with a pre-trained model and fine-tune it on new data:- Faster training time
- Better performance with less data
- Leverage knowledge from previous tracks
- Training on a new track similar to previous tracks
- Adapting to different lighting conditions
- Fine-tuning for specific sections of a track
Tips for Better Training
Data Collection
- Quantity: Collect at least 10-20 laps of good driving data
- Quality: Drive smoothly and consistently
- Diversity: Include various scenarios (straight, curves, lighting)
- Recovery: Include recovery maneuvers from edge positions
Training Strategy
- Start simple: Begin with a linear model to verify your pipeline
- Monitor validation loss: Watch for overfitting (validation loss increasing while training loss decreases)
- Use early stopping: Configured via
EARLY_STOP_PATIENCEin config - Experiment with augmentation: Enable data augmentation in config
Data Augmentation
Enable augmentation in your config to increase training data diversity:Troubleshooting
Low accuracy / High validation loss
- Collect more diverse training data
- Try a more complex model architecture
- Enable data augmentation
- Verify calibration values are correct
Overfitting (validation loss increasing)
- Reduce model complexity
- Enable data augmentation
- Collect more diverse data
- Reduce number of epochs
Out of memory errors
- Reduce
BATCH_SIZEin config - Reduce image resolution (
IMAGE_W,IMAGE_H) - Close other applications
- Use a machine with more RAM/GPU memory
Model file not found
- Ensure the
models/directory exists - Check file path is correct and absolute
- Verify write permissions
Next Steps
After training:- Test your model: Use
donkey tubplotto visualize predictions - Create a video: Use
donkey makemovieto see model performance - Run autonomous mode: Test on your car with
python manage.py drive --model ./models/pilot.h5 - Iterate: Collect more data where the model struggles and retrain
- Track models: Use
donkey modelsto view your model database
