Code Monkey home page Code Monkey logo

behavioral-cloning's Introduction

Behavioral Cloning

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

My project includes the following files:

  • 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

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

Model Architecture and Training Strategy

Model architecture

First I tried to use transfer learning with ResNet with provided weights, but on my machine (only CPU training) it was slow to train and unstable, so I decided to switch to simpler model with some adjustments.

Project uses NVIDIA inspired model with additional layer on top to allow model to control color scheme it uses.

Final architecture is:

  • Normalization
  • Cropping layer
  • Convolution 1x1x3 (Color space choice)
  • LeakyReLU activation
  • Convolution 5x5x24
  • LeakyReLU activation
  • Convolution 5x5x36
  • LeakyReLU activation
  • Convolution 3x3x64
  • LeakyReLU activation
  • Max pooling 2x2
  • Dropout
  • Convolution 3x3x64
  • LeakyReLU activation
  • Flatten
  • Dense (100)
  • LeakyReLU
  • Dropout
  • Dense (50)
  • LeakyReLU
  • Dropout
  • Dense (10)
  • LeakyReLU
  • Dropout
  • Dense (1)

To reduce overfitting, the model contains dropout layers. Moreover, different training and validation sets were applied to prevent overfitting on original data, although MSE cannot show real improvement of the learning, so actual performance was measured by running on first and second track. LeakyReLU has shown itself more effective than ReLU with its capability to restore "dead" neurons. The model used an adam optimizer with learning rate of 0.001.

Training data

To train the model, provided Udacity dataset was used along with captured sections of both tracks.

To capture correct behavior, additionally, I recorded several laps on the first track and second track with some recovery at hard corners and driving on inner radius of the turns to check how it will affect the model behavior. However, later I decided to abandon second track records, as they were representing not suitable data for teaching a model.

Along with center images, I used images from left/right cameras, adjusting the angle accordingly to ±2 degrees.

To augment data set, I used several techniques, including additional shadows, more dark/bright images, flipping and horizontal translation.

alt text alt text alt text alt text

After the collection process, I had around 60.000 data points. However, in this data there was strong bias towards 0 steering angle, so I removed 90% of around 0 data and put the data with step of 0.04, which equals 1/25, or 1 degree angle in simulator.

alt text Final dataset created for training (without augmentation)

I finally randomly shuffled the data set and put 30% of the data into a validation set. All the augmentations were applied "on the fly" in generator. The model was trained only for 5 epochs, as later the training has shown no further improvement and was overfitting heavily.

Network visualizations

Color space choice

alt text

alt text

alt text

First layer visualizations

alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text alt text

Possible further work

  • Work on generalization to create model which could run on first and second track.
  • Try different parameters with shift augmentation to better control turns.
  • Experiment with different tracks and input data to generalize data further and improve driving.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.