Deep Neural Network from scratch on Image Classification - Dogs or Cats?

Phuong T.M. Chu and Hai Nguyen

Deep Neural Network from scratch on Image Classification - Dogs or Cats? is the project that we finished after the 5th week of studying Machine Learning.

INTRODUCTION

Dogs vs. Cats dataset provided by Microsoft Research contains 25,000 images of dogs and cats with the labels

  • 1 = dog
  • 0 = cat

Project goals:

  1. Building a basic deep neural network from scratch to classify dogs and cats images

  2. Tunning the hyperparameters of the model in order to achieve high accuracy. This project explores the applicability of deep neural network by tunning these hyperparameters:

    • Learning rate
    • Number of hidden layers
    • Number of nodes in each hiden layers
    • Number of iterations

BUILDING DEEP NEURAL NETWORK FROM SCRATCH

In this notebook, we implemented all the functions required to build a deep neural network.

Notation:

  • Superscript denotes a quantity associated with the layer.
    • Example: is the layer activation. and are the layer parameters.
  • Superscript denotes a quantity associated with the example.
    • Example: is the training example.
  • Lowerscript denotes the entry of a vector.
    • Example: denotes the entry of the layer's activations).

The initialization for a deeper L-layer neural network is more complicated because there are many more weight matrices and bias vectors. When completing the initialize_params, we made sure that our dimensions match between each layer. Given is the number of units in layer . Thus for example if the size of our input is (with examples) then:

Shape of W         Shape of b            Activation                                                               Shape of Activation                     
Layer 1
Layer 2
Layer L-1
Layer L

Remember that when we compute in python, it carries out broadcasting. For example, if:

Then will be:

Mathematical expression of the algorithm:

Foward propagation:

The linear forward module (vectorized over all the examples) computes the following equations:

where . And the activation functions:

Cost function

Note that denotes elementwise multiplication.

Backward propagation

The three outputs are computed using the input .Here are the formulas we need:

CONCLUSION

We achieved the Accuracy score of 65.2% which is better than the Accuracy score of Logistic Regression Model in sklearn (57.6%). Our hyperparameters are:

  • Learning rate = 0.001
  • Number of hidden layers = 5
  • Number of nodes in each hidden layers = [32,64,128,256,512]
  • Number of iterations = 2500