Skip to main content
The 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

string[]
required
Path(s) to tub directories containing training data. Multiple tubs can be specified:
string
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.
string
Model architecture type to use for training. Common types:
  • linear: Simple linear model (fastest, least accurate)
  • categorical: Categorical output model
  • inferred: Model with inferred steering
  • latent: Latent space model
If not specified, uses DEFAULT_MODEL_TYPE from config.
string
default:"./config.py"
Location of the config file to use. Default is ./config.py in the current directory.
string
default:"./myconfig.py"
Location of your custom config overrides file. Default is ./myconfig.py.
string
default:"tensorflow"
AI framework to use for training:
  • tensorflow: TensorFlow/Keras (default)
  • pytorch: PyTorch
If not specified, uses DEFAULT_AI_FRAMEWORK from config.
string
Path to a checkpoint file to resume training from (PyTorch only).
string
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.
string
Comment to add to the model database for tracking purposes. Use double quotes for multiple words:

Training Process

The training process:
  1. Loads data from specified tub(s)
  2. Preprocesses images and normalizes inputs
  3. Splits data into training and validation sets
  4. Trains the model using the specified architecture
  5. Saves the trained model to the output path
  6. 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 in config.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:
Benefits:
  • Faster training time
  • Better performance with less data
  • Leverage knowledge from previous tracks
Use cases:
  • 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

  1. Quantity: Collect at least 10-20 laps of good driving data
  2. Quality: Drive smoothly and consistently
  3. Diversity: Include various scenarios (straight, curves, lighting)
  4. Recovery: Include recovery maneuvers from edge positions

Training Strategy

  1. Start simple: Begin with a linear model to verify your pipeline
  2. Monitor validation loss: Watch for overfitting (validation loss increasing while training loss decreases)
  3. Use early stopping: Configured via EARLY_STOP_PATIENCE in config
  4. 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_SIZE in 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:
  1. Test your model: Use donkey tubplot to visualize predictions
  2. Create a video: Use donkey makemovie to see model performance
  3. Run autonomous mode: Test on your car with python manage.py drive --model ./models/pilot.h5
  4. Iterate: Collect more data where the model struggles and retrain
  5. Track models: Use donkey models to view your model database