GithubHelp home page GithubHelp logo

sasankyadati / handwritten-digit-classification-using-cnn Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 1.76 MB

A classifier to accurately classify the images of handwritten digits using Convolutional Neural Networks.

Python 100.00%
deep-learning deep-neural-networks convolutional-neural-networks cnn cnn-keras keras tensorflow mnist mnist-classification mnist-dataset classification image-classification

handwritten-digit-classification-using-cnn's Introduction

Handwritten-Digit-Classification-Using-CNN

The objective of this project is to build a image-classifier using Convolutional Neural Networks to accurately categorize the handwritten digits. The data for this project can be found here and the files are expected to be stored in the folder "/data/" relative to the repository.

Convolutional Nerual Networks (CNNs)

Convolutional Neural Networks are a special type of neural networks which are very effective in image recognition and classification. They are powerful as they make use of spatial relationships among the features.

There are four main operations in a typical CNN.

1.Convolution
2.Non Linearity
3.Pooling / Sub Sampling / Down Sampling
4.Fully Connected Layer

To learn more about CNNs, go here.

Network Architecture

We use three types of layers, in this model. They are the convolutional layer, pooling layer and fully connected layer. For this problem, I have defined the following network architecture.

Note: The input is a sample set of 60,000 images, where each image is 28x28 pixels with 1 channel.

The first layer is a Convolutional layer with 20 filters each of size (6,6) followed by another Convolutional layer with 20 filters each of size (3,3). Then, we have a Max Pooling layer of size (4,4).

Similarly, I have defined same set of layers with Convolutional layer having only 10 filters this time. All the Convolutional layers defined above have ReLU as activation function.

Then there are fully connected layers with 30 units in the first and 10 (no. of o/p units) in the second. The first layer uses tanh as activation function and the second one uses softmax.

I also introduced dropouts in between the stacks of layers to avoid overfitting. The key idea behind dropout is to randomly drop units along with their connections to prevent units from co-adapting too much. Read more here.

MNIST Data

The data can be found and is described here.

Environment Setup

I recommend using Anaconda for running the script. Run the following command on conda shell to create a new environment with all the required packages.

conda env create -f mnist-env.yml

The mnist-env.yml file can be found in the repo, which contains details of all the required packages to run the script.

Training

You can begin training the classifier by running the following command. Make sure you have activated the environment before you run the script.

python mnist-classifier.py

I was able to achieve 97.14% accuracy on training data and 97.86% on test data. I encourage you to play with the architecture and the parameters to see what you are able to achieve. Feel free to discuss the same.

Classifying New Images

The images in MNIST dataset contains only greyscale images and almost all of them are clean. This is because of the purpose the creators had while creating the dataset. So, there is a need for some preprocessing.

First off, the images should be converted to greyscale. This is fairly obvious if you have gone through the training script, where we define the number of channels as 1 in the input format.

Secondly, all the images should be resized to (28,28) for the same reason mentioned above.

Now, you're ready to make predictions on custom images!

handwritten-digit-classification-using-cnn's People

Contributors

sasankyadati avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.