This project demonstrate basic self driving car model using udacity car driving simulator. In this project we will be building a Convolution Neural Network model to predict the steering angle for a virtual car in the simulator running at a constat speed.The goal is to drive the car in the simulator autonomously for a full lap without deviating from the main track/road.
Udacity self driving car simulator is used testing and training our model.
First create a project folder structure.
Create 'autopilot_project' folder for keeping all required files and modules for this project.
mkdir autopilot_project
Under this folder create a 'data_set/train_data' , 'data_set/test_data' folder for storing training and test driving data.
cd autopilot_project
mkdir -p data_set/train_data # for storing training driving data
mkdir -p data_set/test_data # for storing validation drivng data
Then clone this repository to 'autopilot_project' folder with below command.
git clone https://github.com/asujaykk/Self-Driving-car.git
Then clone UDACITY 'CarND-Behavioral-Cloning-P3' repository to this folder (for finally testing your model)
git clone https://github.com/udacity/CarND-Behavioral-Cloning-P3.git
Also create an anaconda virtual environment 'tensgpu_1' with the 'autopilot_project/Self-Driving-car/anaconda_env/tens_gpu_self_driving_car.yaml' file for training and testing the keras model.
conda env create -f autopilot_project/Self-Driving-car/anaconda_env/tens_gpu_self_driving_car.yaml
Download udacity pre-build term1 driving simultor with below command (term1 beta simulator).
wget https://s3-us-west-1.amazonaws.com/udacity-selfdrivingcar/Term1-Sim/term1-simulator-linux.zip
To get different versions or to build a custom simulator, then please check UDACITY self-driving-car-sim repository here https://github.com/udacity/self-driving-car-sim
After downloading please extract 'term1-simulator-linux.zip' file to 'autopilot_project' folder. Open terminal and navigate to 'autopilot_project/term1-simulator-linux/beta_simulator_linux' and make 'beta_simulator.x86_64' (or beta_simulator.x86 based on your system architecture) as executable with the following command.
sudo chmod +x beta_simulator.x86_64
Activate the anaconda environmnet 'tensgpu_1' that was created before using below command.
conda activate tensgpu_1
Then run 'model_train.py' to create a model and train it with the training and test data set that was created before.
python3 model_train.py --train_csv_file 'path to training driving_log.csv file' --test_csv_file 'path to test driving_log.csv file' --batch_size 32 --epochs 50 1>train.log 2>&1
The above execution will create four different models (for diffrenet learning rates) under the folder 'autopilot_project/Self-Driving-car/models'. Check 'autopilot_project/Self-Driving-car/train.log' to see the progress of training. After successsfull training, revisit the log and check which model had minimum 'loss' and 'val_loss', and choose that as final model for testing.
Note: If your PC have resource constraints then please reduce batchsize to 8 or 16 to avoid 'OOM' error.
Lauch the simulator in autonomous mode For testing the model.
Run the pre-build simulator executable.
Once it is launched, choose Autonomous mode from the main window (Now the simulator should be ready to accept a connection).
Change the working directory to 'autopilot_project/CarND-Behavioral-Cloning-P3'
Activate the anaconda environmnet 'tensgpu_1'.
conda activate tensgpu_1
Then run 'drive.py' with the folllwoing command.
python3 drive.py 'path to the craeted model.h5 file'
Note: If you are facing any issues then please check issues under 'https://github.com/udacity/CarND-Behavioral-Cloning-P3' repo to get solutions.
If the environment is proper and if the script able to make a connection with the simulator then the car in the simulator start running at 9kmph, and it will try to adjust it's steering angle to keep the car always on the track.
If the car is able to maintain on the track for a full lap, then your model is performing well :)
If The car is not always stays on the track, then the model is poorly performing :( , then retrain the model with more data and with reduced batch size. and test it again and agian until a good performance is achived.
I also kept a trained model 'save_at_8.h5' at https://drive.google.com/file/d/1VkyFqVZIGY8Oayi_i3R4czwdgNHZKxxt/view. This model will work perfectly with term1-beta simulator track1. The model performed well even with max speed of 30Mph.
The following GIF shows the output of 'save_at_8.h5' model.
References: