Lane Following Autopilot with Keras & Tensorflow.

Jan 2017

Create a keras model that accepts images and outputs steering angles so that it can control a car and keep it between two white lines.

This document walks through how to create a convolution neural network using Keras+Tensorflow and train it to keep a car between two white lines.

Updated Feb 2, 2017 - Thanks to comments on Hacker News, I've updated this doc to use more machine learning best pratices.

Here is a Raspberry Pi controlled RC car using the autopilot crated in this document to drive between the lines. See the donkey repository for instructions to build your own car.

'self driving rc car'

In [1]:
import os
import urllib.request
import pickle

%matplotlib inline
import matplotlib
from matplotlib.pyplot import imshow

Get the driving data

The dataset is composed of ~7900 images and steering angles collected as I manually drove the car. About 2/3 of the images are with the car between the lines. The other third is of the car starting off course and correcting by driving back to between the lines.

In [2]:
#downlaod driving data (450Mb) 
data_url = ''
file_path, headers = urllib.request.urlretrieve(data_url)

The dataset consists of 2 pickled arrays. X are the image arrays and Y is an array of the coresponding steering angles.

In [3]:
#extract data
with open(file_path, 'rb') as f:
    X, Y = pickle.load(f)
print('X.shape: ', X.shape)
print('Y.shape: ', Y.shape)
X.shape:  (7892, 120, 160, 3)
Y.shape:  (7892,)
<matplotlib.image.AxesImage at 0x7f3f6b577828>