A Handwritten Digit Classifying App


It's really interesting how machine learning algorithms are able to perform tasks no machine could previously do. Consider the task of recognising handwritten letters. Your handwriting is not the same as mine and in fact all handwritings are unique!

If you have ever dealt with any programming before, you would know that all programs work on a set number of rules. "If this, then that" is the general pattern followed. If we used this rule based approach to detect handwritten letters, it would fail due to the irregularity and variations in handwritten characters.

So how do we then detect these handwritten letters? The answer lies in machine learning!

Using machine learning we don't set the rules! We give the data and the output to the algorithm and it figures out the rules! The below diagram explains this statement:

Now that we know what to do, let's actually try doing it!

A Simplification

To detect handwritten letters, we would need data of 26 letters written by different people.

Let us simplify our problem statement by classifying only handwritten digits from 0-9.

Step 1: Get the data

For this model, I used images from the MNIST dataset. This dataset contains ~55000 images of handwritten digits from 0-9. Below is a few images from this dataset:

Step 2: Build the model

The next step is to actually build the program to classify these digits. For this task I used a convolutional neural network to classify the digits.(Code is at the end of this blog post).

Step 3: Training and Testing the model

After training the model for around 10 epochs (10 iterations of the entire dataset), it had an accuracy of ~98% which is really good!! The model was able to classify the digits correctly 98% of the time.

I then tested the model with my own images and it did a really good job at classifying them. However it was a little complicated to feed the test images to the model and so I thought why not create an app which would simplify this UI!

Step 4: Creating the app

Creating the app was pretty difficult but it was possible with the help of several online resources. The app generates a math question, eg 2+3 for which one needs to "write" out the answer:)

The whole project took around 2 weeks to complete but it was really satisfying doing it.

I should mention that this project was created last December but I did not publish any blog as I did not have a website then:)

Now that that's aside, drumrollllll and here is the final result of all the training:


This app could be used to teach maths to children in a fun and satisfying way but there are so many other applications of this as well. Nowadays character recognition is used by several companies in their products ranging from handwriting based search to handwritten based messaging apps and so on. Comment below any other applications you may have:)

Link to the Machine Learning model:

It would be really great if you could like and share this blog to anyone who may find it useful. Also please leave your comments below for any suggestions, improvements etc!

202 views2 comments

Recent Posts

See All