Skip to main content
Keras model parts use deep learning to predict steering and throttle from camera images and other sensor inputs.

Base Class: KerasPilot

All Keras models inherit from KerasPilot. Location: donkeycar/parts/keras.py:49
Key Methods:
  • create_model() - Define neural network architecture
  • compile() - Set optimizer, loss, and metrics
  • run(img_arr, *other_arr) - Inference during driving
  • train() - Train the model
  • load(model_path) - Load saved model
  • interpreter_to_output() - Convert raw output to control values

Model Types

KerasCategorical

Discretizes steering and throttle into bins using categorical cross-entropy. Location: donkeycar/parts/keras.py:256
Architecture (default_categorical):
Features:
  • Converts continuous values to discrete bins
  • Better gradient flow for categorical data
  • Provides confidence distribution over choices
  • Default: 15 bins for steering, 15 for throttle
Usage:

KerasLinear

Direct regression to continuous steering/throttle values. Location: donkeycar/parts/keras.py (similar to KerasCategorical)
Architecture (default_n_linear):
Features:
  • Direct regression to continuous values
  • Simpler output interpretation
  • MSE or MAE loss functions
  • Good for smooth control

KerasIMU

Multi-input model using camera + IMU data. Location: donkeycar/parts/keras.py
Architecture:
Usage:

KerasLSTM / KerasRNN

Recurrent models that consider temporal sequences. Location: donkeycar/parts/keras.py
Architecture:
Features:
  • Considers multiple frames (temporal context)
  • Better for handling motion blur, occlusions
  • Requires sequence buffering
  • Higher computational cost

Model Training

Training Configuration

In myconfig.py:

Training Command

Training Script Example:

Model Inference

Loading Models

Using in Vehicle

Model Architectures

Available Architectures

Location: donkeycar/parts/keras.py
  • default_categorical - Standard categorical model
  • default_n_linear - Standard linear regression
  • default_imu - Multi-input with IMU
  • default_lstm - LSTM for sequences
  • default_3d_conv - 3D convolutions for video
  • default_latent - Variational autoencoder

Custom Architecture

Model Export

TensorFlow Lite

For edge deployment:

SavedModel Format

Performance Optimization

Model Quantization

Mixed Precision Training

Common Issues

Model Overfitting

  • Reduce model complexity
  • Add more dropout layers
  • Increase training data
  • Use data augmentation
  • Add L2 regularization

Poor Performance

  • Check training/validation loss curves
  • Verify data quality (clean bad examples)
  • Try different learning rates
  • Use transfer learning
  • Ensure proper train/test split

Memory Issues

  • Reduce batch size
  • Use model quantization
  • Convert to TFLite
  • Use gradient checkpointing

Next Steps