Building a Real-Time digit classifier using MNIST (99.17% accuracy)

Lukas Gisder-Dubé
Level Up Coding
Published in
5 min readJul 1, 2020

--

You can have a look at the deployed interactive demo or have a look at the github repo.

MNIST is a classic dataset for training image classifiers using Deep Learning. The dataset consists of 70,000 handwritten digits, stored as images. Playing around with Deep Learning for a bit now, I thought it might be fun to see what performance is possible to achieve as someone being new to the field.

My idea was to combine a classifier with a small Frontend to let the user draw a digit with the mouse and see the results in real time. After all, having a piece of code perform well is one thing, but making it approachable for users is another.

Being in Web Development for a couple of years now, building the frontend was not too much of a problem. I know I could use canvas to let the user draw. Around that, I would need a basic web page, displaying the results, loading state etc. More on that later.

Training the model

As with the previous Deep Learning project, I used the fast.ai library to create and training a neural network. The library gives you all the tools needed (especially for beginners) to get started quickly. You simply load in the data, pick a base architecture, provide some base variables and let the model train itself.

Providing the data was easy, at least I thought so in the beginning. The dataset exists already and I would only need to download the data and provide it for the model. After downloading and unpacking the archived data, I noticed that it was pretty much unformatted data, i.e. “unsigned bytes”. While there is most probably a way to feed that to the neural network, I was expecting the data to be as single PNG files. I tried running some scripts to convert that, but finally found this github repo with the dataset converted to PNG.

With the data provided in a usable format (for me), I could go ahead and train the model. I used resnet34 as base architecture for a CNN and trained the model. Out of the box, the model achieved an accuracy of ~98.9%, which is amazing. Being…

--

--

Passionate about technology, design, startups and personal development. Bringing ideas to life at https://dube.io