Project 5: Face detection with a sliding window

In this project, I need to implement a sliding window for face detection. The major steps are listed below.

  1. (Image with faces)Get postive features by Histogram of Gradients(HoG) descriptor. The main function used here is
    vl_hog
  2. (Image without faces)Get random negative features by HoG.
  3. Train linear SVM classifier from postive and negative features. The main function used here is
    vl_trainsvm
  4. Run classifier on test images at multiple scales and do non-max suppression.

get_positive_features.m

The first part of this project is to get postive features. It is very easy to code because all face traning pictures are 36x36 pixel so I just need to implement HoG on each picture.

get_random_negative_features.m

In the second part I need to sample random negative examples from scenes which contain no faces and convert them to HoG features. I need to set the images to grayscale to match features of face images. To get random negative features, I select row and colum points randomly which are at least template size above the bottom and left from the right to make sure the random sample negative features inside the image. And then do HoG on each image to get enough negative samples which I set the total sample number is 10000.

classifier training

Here I use vl_trainsvm to train a linear svm classifier from the positive and negative examples. I coded this inside pro5.m and the parameter lambda is important. Small value of lambda work better but lead longer running time. I used the value of lambda 0.0001 as the instruction suggest. The confidence can be generated from weight*window_vector + bias. I set the confidences threshold to be 0.75 to make sure high average precision.

run_detector.m

The last part of this project is to implement a sliding window for face detecion by running the classifier on the test set. I run the classifier at multiple scales(each time multiple 0.9 until the length of image is smaller than the template size) and then run non-max suppression to remove duplicate detections.

Result