Skip to content

This is a project influenced by coursera machine learning course presented nt Prof.Andrew Ng. In this project I used ex4 dataset and implemented exercise4 with python.

License

FarzamTP/Neural-Network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neural Network

This project contains two phases:

  • Pure self implemented gradient descent based neural network
  • non-framework TensorFlow implementation

Self Implemented Gradient Descent (Phase One)

At phase one, I tried to implement the whole forward-propagation and back-propagation on my own and make progress trough the MNIST data set. For this phase I implemented main.py and fed algorithm with given data set according to Deeplearning.ai course on coursera presented by Prof.Andrew Ng on third week's exercise.

Code Features

The implemented main.py code has some features that may help you such:

  • Data restored from data.mat file stores in dataset directory.
  • Model will be saved after training in model directory as parametrized numpy arrays(*.npy).
  • If a previously trained model exists in denoted directory, It will be loaded automatically
  • Accuracy of given data will be computed and displayed at the end of training, or loading model.
  • All methods needed for neural network algorithm is implemented inside main.py.

Accuracy and Cost

The algorithm performs well and will has accuracy of 0.988% over training-set: Cost figure

Result (Phase one)

According to that this is a only one-hidden layer model with one input layer (also known as feature layer) and a output layer, It is pretty simple neural network and for such structure its performance is dominant.

TensorFlow Based Neural Network (Phase Two)

In second part I noticed that although I designed a simple model, It runs on CPU, So It is a lot slower than processing on GPU. So I started to impalement my model on file TensorFlow-NN.py with TensorFlow framework which is able to be ran on GPU.

Code Features

TensorFlow-NN.py has some features as well as main.py such as:

  • The cost function is optimized with Adam optimizer
  • TensorFlow.train.Saver is user in the code which can be user for storing or loading model.
  • Some very useful functions like one_hot(), next_batch() are implemented, which will make code simpler and more readable.
  • Model is saved in model/TensorFlow directory at end of every training.
  • A sample from training-set is selected and predicted by model at end of training.
  • TensorBoard is a lot useful here with TensorFlow to demonstrate graphs.

Accuracy and Graph

The algorithm with default parameters will perform like 0.962% over training set. And this is our model's graph which can is downloaded from TensorBoard. Graph Figure

Conclusion

According to denoted details, in such scale data (about 5000 records of 400 feature images) Adam and Gradient Decent algorithm works all good, however Adam optimizer that is implemented in TensorFlow is a lot faster than Gradient Descent.

Note

Here I uploaded pre-trained model for each algorithm for you in model director, Enjoy :)

About

This is a project influenced by coursera machine learning course presented nt Prof.Andrew Ng. In this project I used ex4 dataset and implemented exercise4 with python.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages