This project focuses on Behavioral Cloning for a self-driving car using data generated from a simulated environment. Behavioral Cloning is a machine learning technique where a model learns to mimic human behavior, in this case, human driving behavior, by training on recorded driving data. The project is divided into several Python files: TrainingSimulation.py, utils.py, and TestingSimulation.py.
In this step, driving data from the simulated environment (collected in the AllPackHillTrack directory) is imported and stored in a Pandas DataFrame.
The data is visualized and analyzed to understand the distribution of steering angles. A histogram is plotted to visualize the distribution, and data balancing is performed to ensure a roughly equal representation of different steering angles.
This step loads image paths and corresponding steering angles from the imported data.
The dataset is split into training and validation sets using the train_test_split function. This allows for model training and evaluation on separate data subsets.
Data augmentation techniques, such as translation, zoom, brightness adjustment, and flipping, can be applied to increase the dataset's diversity and improve model generalization. This step is prepared but commented out.
Images are preprocessed by cropping the region of interest, converting to the YUV color space, applying Gaussian blur, and resizing to a specific resolution.
A batch generator is defined to yield batches of preprocessed images and corresponding steering angles. This generator can be used for model training.
The neural network model for behavioral cloning is defined using the Keras library. It consists of several convolutional layers followed by fully connected layers. The model aims to predict the steering angle from input images.
The model is trained using the training dataset generated by the batch generator. Training involves minimizing the mean squared error (MSE) loss function, and Adam optimization is used. Training results, such as loss and validation loss, are monitored.
The trained model is saved to a file (e.g., modelHillTrack3000spe_100e_v2_Right.h5). Additionally, a plot of training and validation loss is generated for evaluation.
This file contains utility functions used in the training process:
importDataInfo: Imports driving data and returns a Pandas DataFrame.balanceData: Balances the data distribution by removing excess samples from over-represented steering angles.loadData: Loads image paths and steering angles from the data.augmentImage: Applies data augmentation techniques to images.preProcessing: Preprocesses images by cropping, resizing, and normalizing.batchGen: Generates batches of preprocessed images and steering angles.createModel: Defines the neural network model architecture.
This file is used for testing the trained model in a simulated environment using a PID (Proportional-Integral-Derivative) controller.
Incoming camera images are preprocessed to match the format used during model training. This includes cropping, resizing, and normalization.
A PID controller is used to control the vehicle's steering and throttle. The controller computes the steering angle and throttle values based on the current speed and the difference between the desired and current steering angles. PID parameters (kp, ki, and kd) are used to fine-tune the controller's behavior.
- Proportional (P) Term (kp): Adjusts the current steering angle in proportion to the error between the desired and current angles.
- Integral (I) Term (ki): Compensates for accumulated error over time and helps eliminate steady-state errors.
- Derivative (D) Term (kd): Predicts future error based on its rate of change and helps prevent overshooting.
The computed steering angle and throttle values are sent to the simulated car to control its movement.
Behavioral cloning is a critical technique in developing self-driving car models. This project demonstrates how to collect, preprocess, and augment driving data and train a neural network to drive autonomously in a simulated environment. Additionally, the PID controller in TestingSimulation.py provides a basic example of control systems used in self-driving cars to maintain vehicle stability and follow desired paths.