Base Class: KerasPilot
All Keras models inherit fromKerasPilot.
Location: donkeycar/parts/keras.py:49
create_model()- Define neural network architecturecompile()- Set optimizer, loss, and metricsrun(img_arr, *other_arr)- Inference during drivingtrain()- Train the modelload(model_path)- Load saved modelinterpreter_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
- 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
KerasLinear
Direct regression to continuous steering/throttle values. Location:donkeycar/parts/keras.py (similar to KerasCategorical)
- 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
KerasLSTM / KerasRNN
Recurrent models that consider temporal sequences. Location:donkeycar/parts/keras.py
- Considers multiple frames (temporal context)
- Better for handling motion blur, occlusions
- Requires sequence buffering
- Higher computational cost
Model Training
Training Configuration
Inmyconfig.py:
Training Command
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
- PyTorch Models - Alternative framework
- Data Stores - Prepare training data
- Custom Parts - Create custom models
