Skip to content

The purpose of this project is to take handwritten digits as input, process the digits, train the neural network algorithm with the processed data, to recognize the pattern and successfully identify the test digits. The popular MNIST dataset is used for the training and testing purposes. The IDE used is MATLAB

License

Notifications You must be signed in to change notification settings

deyjishnu/digit-recognition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

B.Tech Final Year Project - Handwritten Digits Recognition Using Neural Networks

Duration: Oct 2016 – Jun 2017

The purpose of this project is to take handwritten digits as input, process the digits, train the neural network algorithm with the processed data, to recognize the pattern and successfully identify the test digits. The popular MNIST dataset is used for the training and testing purposes. The IDE used is MATLAB

Procedure in short

This project presents a study on recognition of handwritten digits (from 0 to 9) using neural networks from the popular MNIST dataset. I built a two-layer neural network (one hidden layer) and tried different techniques and observed the training set accuracy and test set accuracy. The final network of connections and weights obtained by using 200 hidden neurons and training for 1000 iterations using the 'fmincg' optimization algorithm and regularisation parameter = 0.1, I achieved 98.29% test set accuracy, ie. Test Set Error Percent = 1.71, which is on par with the accuracies achieved using similar classifiers by LeCun and Simard. Other than the 'fmincg' function, I have not used any prebuilt functions. My model: 2-layer NN, 200 HU, Cross-Entropy Loss (without any preprocessing).

Test Set Accuracy achieved with various parameters on the MNIST dataset

Number of hidden neurons Number of iterations (epochs) Training Set Accuracy (%) Test Set Accuracy (%)
25 30 89.9533 90.18
50 30 91.54 91.57
100 30 90.29 90.94
200 100 96.261667 96.07
200 1000 100 98.29

We achieved maximum accuracy of 98.29% (error = 1.71%) on the test set of the MNIST dataset without using any ready-made toolkit.

Code Info (or How to run the code)

Start with the neuralNetwork.m code in the Code folder. This neuralNetwork.m uses many functions, many of which are defined in the other .m files in the Code folder. Adequate comments are provided in the right places for understanding the code.

  • neuralNetwork.m -> Main code

  • .idx3-ubyte -> Contains the original training images and labels

  • loadMNISTImages.m, loadMNISTLabels.m -> Loads the training images and their labels from the original idx3-ubyte files

  • displayData.m -> Displays 2D data in a nice grid

  • nnCostFunction.m -> Implements the neural network cost function for a two layer neural network which performs classification

  • sigmoidGradient.m -> Returns the gradient of the sigmoid function

  • sigmoid.m -> Computes sigmoid function

  • randInitializeWeights.m -> Randomly initialize the weights of a layer of neurons in the neural network

  • checkNNGradients.m -> Creates a small neural network to check the backpropagation gradients

  • validationCurveHoldout.m -> Generates the training and validation errors needed to plot a validation curve that we can use to select regularization parameter

  • fmincg.m -> a function which works similarly to "fminunc"

  • predict.m -> Predicts the label of an input given a trained neural network

  • predictExternalImage.m -> Predicts what digit is contained in an external image for a trained neural network

  • predictPercentExternalImage.m -> Predicts what digit is contained in an external image, along with the probability given a trained neural network

  • neuralNetworkWeights - HU200_EP1000_R0.1.mat, neuralNetworkWeights-98.35.mat, savedNeuralNetworkWeights.mat -> Saved Neural Network weights

Sample Images

Image sets present inside the Sample Images folder are created using Microsoft Paint. These are 28x28 pixel images of digits 0-9 to mimic the MNIST dataset. These images are used for external image recognition.

Where to learn the Basics and More

We have a detailed guide for the project in A layman's guide to the project. Two research papers which helped us:

  1. Handwritten Digit Recognition with a Back-Propagation Network by LeCun et al
  2. A Set of Features Extraction Methods for the Recognition of the Isolated Handwritten Digits by Ouchtati, S and Redjimi, M and Bedda, M

If you want to learn what neural networks are and how to start with Matlab, you can start with this popular course by Andrew Ng.

Acknowledgement

Effective noise removal from external images is a very complex process and requires in-depth knowledge in this domain. And without good noise removal, it is impossible to achieve good success rate in detecting digits from external images.

As we didn’t prioritise on processing of external images over getting good results on test data set, the results on external images is not good and is inconsistent.

The segmentation algorithm can also be vastly improved to identify individual objects from all types of images, without false positives.

About

The purpose of this project is to take handwritten digits as input, process the digits, train the neural network algorithm with the processed data, to recognize the pattern and successfully identify the test digits. The popular MNIST dataset is used for the training and testing purposes. The IDE used is MATLAB

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages