One of the challenges in training and testing ML algorithms is to obtain high quality data: the live data your algorithms will be working on often isn’t availabe from the word go and even if it is, it may not contain all the features you want to train your algorithm on.
One approach to dealing with this is to generate data using simulations – this gives you full control both of the features contained within the data and also the volume and frequency of the data.
This project focused on obtaining the data set through a simulator. The simulator consists of a vehicle that drives on two tracks. One easier than the other. The simulator has two modes of use. The first is to obtain data to train the model. The second is to test the model trained previously. The was provided by Udacity, you can find the repository here.
The model was based on the architecture proposed by NVIDIA in this paper. The model is named End to End Learning.
Behavioral Cloning Project
The goals / steps of this project are the following:
- Use the simulator to collect data of good driving behavior
- Build, a convolution neural network in Keras that predicts steering angles from images
- Train and validate the model with a training and validation set
- Test that the model successfully drives around track one without leaving the road
- Summarize the results with a written report
Here I will consider the rubric points individually and describe how I addressed each point in my implementation.
My project includes the following files:
- download_data.py containing the script to download the data
- model.py containing the script to create and train the model
- drive.py for driving the car in autonomous mode
- model.h5 containing a trained convolution neural network
- writeup_report.md or writeup_report.pdf summarizing the results
First , run download_data.py
to get data. use:
python download_data.py
Second, explore the data using DataExploration.ipynb
. Use:
jupyter notebook DataExploration.ipynb
Using the Udacity provided simulator and my drive.py file, the car can be driven autonomously around the track by executing
python drive.py model.h5
The model.py file contains the code for training and saving the convolution neural network. The next shows the pipeline I used for training and validating the model, and it contains comments to explain how the code works.
The model consists of 3 a convolution neural network with 5x5 filter sizes and depths between 24 and 48. And 2 a convolution neural network with 3x3 filter sizes and depths of 64. Finally, the model has 3 last fully-connected layers.
The model includes ELU layers to introduce nonlinearity (see , and the data is normalized in the model using a Keras lambda layer.
I obtained 3 images by each original image. One of them corresponds flipped image and, in the other, the brightness was changed arbitrarily.
to flip the image, the cv2.flip()
was used. The corresponding angle was multiplied by -1. The brightness was randomly modified to simulate lights environment conditions. To do that, the image was converted to HSV and the channel V was changed randomly. The image was turned back to RGB space.
To the left and right camera images, the same process was applied but in this case, in the corresponding angle was corrected by a factor of 0,2.
I decided to shuffle the images so that the order in which images comes doesn't matters to the CNN
The model contains dropout layers in order to reduce overfitting .
The model was trained and validated on different data sets to ensure that the model was not overfitting. The model was tested by running it through the simulator and ensuring that the vehicle could stay on the track.
The model used an adam optimizer, so the learning rate was not tuned manually. I choose Mean Squared Error (MSE) as loss function.
I just examine the data given by Udacity() and found that the data correspond to 9 laps in the first easy track. The data was pre-proccesed to get augmented data in order to generalize the model. First, the data was cropped from top because I did not wanted to distract the model with trees and sky and 25 pixels from the bottom so as to remove the dashboard that is coming in the images.
I finally randomly shuffled the data set and put 20% of the data into a validation set.
I used this training data for training the model. The validation set helped determine if the model was over or under fitting. The ideal number of epochs was Z as evidenced by ... I used an adam optimizer so that manually training the learning rate wasn't necessary.
To test the model I recurred to autonomous mode on the simulator to get the views of the car. With the images collected I used video.py
to make a video with the images obtained. Thus, I evaluate the performance of the model. The test video can be seen