/Face-Detection-using-CNN

This repository contains code base for an end to end implementation of a project titled "Face Detection using CNN"

Primary LanguagePython

PROJECT TITLE: FACE DETECTION USING CNN aka ConvNets

DESCRIPTION:


This repository gives budding Deep Learning enthusiats a gentle introduction to the topic of Deep Learning.

In this repository , I will list down all the steps needed to get started with your first project in Deep Learning.

So go ahead, Fork this repo and get started with Deep Learning.

CONTENTS:

  1. Dataset download
  2. Tools & Libraries
  3. Code
  4. Instructions to run the code
  5. Future improvements

EXPLANATIONS & STEPS:

  1. Dataset download:
    For this project we will be using the UMD face dataset which can be downloaded from: UMD Dataset

    UMD Face Dataset

    Go ahead and download the Batch 3 dataset, which will have faces of personalities and and .csv file that contains the annotations to crop out the face from each of the images:
    Batch 3

1.1. Data Preprocessing Input/Output Code-UMD.py:
In the next step, we need to write a code that would read the annotations from the .csv file , crop out the faces to create the positive dataset and crop out the background to create the negative dataset.The code should be self sufficient and modular so that when parameters like "dataset path", "# of train images", "# of test images", "color/gray", the code should perform all the tasks and divide the dataset into a folder structure as below:

Train/Test Folder Structure

2. Tools & Libraries:
2.1 In this project we will be using the Keras Deep Learning Library and we will be running it on top of the Tensorflow backend.
Keras & Tensorflow

Instructions on how to install Keras & Tensorflow on an Ubuntu machine are available online.
2.2 The code editors we will be using are Anaconda with OpenCV,Numpy,Scipy support.

3. Code-CNN_code.py:
The python file CNN_code is the main code which encapsulates the CNN architecture that was used for this project.

The steps performed by the code are as follows:

3.1: In this code, I have used a simplistic CNN architecture as below:

2D CONVOLUTION LAYER->2D MAX POOLING->2D CONVOLUTION LAYER->2D MAX POOLING->2D CONVOLUTION LAYER->2D MAX POOLING->2D CONVOLUTION LAYER->2D MAX POOLING->FULLY CONNECTED->FULLY CONNECTED

3.2: In this code, I have used Binary CrossEntropy as the Loss Function , the RMSProp as the Gradient Descent algorithm:

3.3 The hyperparameters used are as follows:

LEARNING RATE =1e-4

STEPS PER EPOCH =100

EPOCHS =30

VALIDATION STEPS =50

4. HYPER PARAMETER OPTIMIZATION:
The tune the hyperparameters, we run a random search over the hyperparameter space, by sampling the Learning Rate & Regularization from a uniform distribution.

The optimal set of hyperparameters after running a coarse search and fine search are as follows:

COARSE SEARCH:

Maximum Testing Accuracy=96.89%

Minimum Testing Loss=0.094

Value of optimum Learning Rate=4.48e-4

Value of optimum Regularization=2.27e-5


FINE SEARCH:

Maximum Testing Accuracy=97.79%

Minimum Testing Loss=0.1034

Value of optimum Learning Rate=8.29e-4

Value of optimum Regularization=3.91e-3


The plots of TRAINING VS TESTING ACCURACY and TRAINING VS TESTING LOSS:

TRAINING VS TESTING LOSS

TRAINING VS TESTING ACCURACY
5. SETUP INSTRUCTIONS:
The entire setup instructions to run the code can be found in README.txt