Hi, I'm Artur Olszak and this is my programming blog :-)
You can contact me here.
Some links: LinkedIn, GitHub, Stackoverflow, SoundCloud.

2017-03-09 14:55:59

Self-Driving Car - Vehicle Detection using SVM

I have joined Udacity to learn Self-Driving Car technology and one of the projects in the first term was vehicle detection using machine learning techniques. That was really interesting project. Check-out my approach to the problem.

The goals / steps of this project are the following:

  • Perform a Histogram of Oriented Gradients (HOG) feature extraction on a labeled training set of images
  • Apply a color transform and append binned color features, as well as histograms of color, to your HOG feature vector
  • Train a classifier Linear SVM classifier
  • Implement a sliding-window technique and use your trained classifier to search for vehicles in images
  • Create a heat map of window detections
  • Estimate a bounding box for vehicles detected
  • Run the pipeline on a video stream and output a video with tracked vehicles

Histogram of Oriented Gradients (HOG)

The code for this step is contained in the 3rd code cell of the IPython notebook.

I started by reading in all the vehicle and non-vehicle images. Here is an example of one of each of the vehicle and non-vehicle classes:

alt text alt text

I then explored different color spaces and different skimage.hog() parameters (orientations, pixels_per_cell, and cells_per_block). I grabbed first car image and displayed it to get a feel for what the skimage.hog() output looks like.

Here is an example using the YUV color space and HOG parameters of orientations=9, pixels_per_cell=(8, 8) and cells_per_block=(2, 2):

alt text

I tried various combinations of parameters and I have decide to make a fair trade-off between car feature recognition and speed of processing it. The problem, which I was was facing was to find best color space for both black and white car. I've decided to use those parameters:

  • first channel 'YUV' color space
  • orientations equal 9
  • pix_per_cell equal 8
  • cell_per_block equal 2

Classifier training

Firstly I had iterate over whole dataset in order to get HOG features from all images. After doing so I have prepared labels for both vehicles and not vehicles images. The dataset and labels were splitted into train and test sets with propotion 8:2 as usually.

LinearSVC classifier was trained with usage of Pipeline and StandardScaler objects. Overall time of training was less than 10s and accuracy was equal 98%.

Training code is contained in 5th cell of the notebook.

Sliding Window Search

In order to implement Window Search, I have implemented function for preparing all windows awailable for the default image size. Windows were created only for the bottom half of the images (without sky), with 50% edge overlapping and with different sizes depending on the vertical position - the more down it goes, the bigger the windows were.

alt text alt text

I was checking each window and classifying it in order to know is there a car or not. Because of overlapping character of the windows I was able to generate heatmaps and find spots with high classifications of the cars.

alt text

Code for this part is contained in cells 7 and 8 of the notebook.

Pipeline optimization

Ultimately I've decided to use only first channel of the 'YUV' color space, plus spatially binned color and histograms of color in the feature vector, which provided a nice result.

Below you can see how the pipeline performs with test images:

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

Video Implementation

1. Lint to final video

Here's a video with preview.

2. False positives filter

I recorded the positions of positive detections in each frame of the video. From the positive detections I created a heatmap and then thresholded that map to identify vehicle positions and remove false positives. In order boost correct classification of the cars I have implemented heatmap list for keeping last 20 in memory and use sum of them in order to determine final heatmap. This solution gave me better stability of the vehicle tracking.

I then used scipy.ndimage.measurements.label() to identify individual blobs in the heatmap. I then assumed each blob corresponded to a vehicle. I constructed bounding boxes to cover the area of each blob detected.


I have decided to implement the solution as it was suggested in the course - using Linear SVM for car classification. It turned out that training was really fast, but in the end classifications were not always true. I think that Deep Learning solution would give much better results.

<-- back


Since 2013