The Machine Learning Blog

How to train a Machine to recognize handwritten numbers in a picture (or anything else for that matter)

handwritten numbers

Recognizing hand written numbers

In this post, I will explain how to use Machine Learning to build a piece of software that is able to recognize handwritten numbers. I will also explain what other applications this could have for you and your business. This being said, I will not go into implementation details, nor into the mathematics of how this works, the post will just explain the general idea behind this principle.

 

For a machine, recognizing something in a picture is not an easy task.
Machines are quite stupid and cannot understand images. They can only understand the existence or the absence of pixels. We therefore have to put everything in terms they can understand if we want them to make such a simple task...

 

excuse me robot

Analyzing images pixel by pixel

If we use 20x20 pixels images, each one will have a total of 400 pixels... And if they are in black and white, each pixel will have a level of gray, going from 0 (completely white) to 100 (completely black).
Every one of the images in my training set can be represented by a series of 400 numbers, each one with values ranging from 0 to 100.

pixel reading

If we replace the image picture with all the numeric values of its pixels, we will be able to feed them to the machine and apply some mathematics to train our Neural Network.

 

It takes 400 inputs to give 1 output

We will use supervised learning with a neural network that will be able to classify any given image. If you haven't read my blog on what Neural Networks are, read it here.
The idea is to create a mathematical model that will take 400 inputs (pixel values) and calculate the influence (weight) each value has on the outcome. 
At this point, our Machine Learning model would look something like this:

 

simple neural network

For the moment, we only have one example, so our model will not able to be very precise at calculating the importance of each pixel of what represents the number 3 in a given image... That is why it is very important to have large amounts of data.
This will allow us to feed our model with more training examples and different variations of the same number 3.

 

Handwritten 3s

 

If we have enough examples of how the number "3" is written, we can feed them to our model and we will be able to compute the impact (weight) that each pixel level of blackness had on making that particular image a number 3.

 

The dataset to train the model

In order to train a piece of software to recognise hand written numbers, we first need to start by providing it with lots of examples. Gladly for us, the MNIST Database of handwritten digits was uploaded to the web by a group of very altruistic people who we cannot thank enough! This dataset contains 60 thousand black and white handwritten images, each one made from 20x20 pixels.
​When plotted in a math software like Octave (widely used for machine learning), they look something like this.

 

octave handwritten numbers

Multilayer neural networks

In my post about neural networks, I explained the concept of multi layer neural networks with hidden inputs.
If you already read my post, you should know by now that linear models do not always fit your data, thus the importance of having hidden layers.
What this means concretely, is that our 400 inputs will generate a given number of "hidden" inputs and that these will be the ones that ultimately decide the output of my model.
Our Machine Learning model now looks something like this:

neural network

Each one of the lines interconnecting the inputs are called "weights" or "parameters".
The goal of machine learning is to use the training examples to compute the "parameters" that best predict if a completely new image is a number 3 or not.

 

One vs all classification

Needles to say, a software that predicts if a number is a 3 or not, is completely worthless. What we need is a piece of software that is able to distinguish any new image and correctly guess what number it is. 
Concretely, what we need to do is train 10 different mathematical models.
Or Neural Network would look something like this.

neural network multi classification

Our Machine Learning model will be able to take any given new image, apply the learning weights (parameters) that we found while training it and give us the 10 different probabilities of it fitting in each model.
For instance, an image can have:

  • 10% chances of being a 0
  • 15% chances of being a 1
  • 86% chances of being a 2
  • etc

What we will do is simply pick up the highest probability and make our prediction based on that information.
That is all there is to it :-)

smart guy

Why go through all this trouble?

Why go through all this trouble to make a machine be able to achieve such a simple task that a human can do in less than a second?
Well, you could pay a human the minimum wage to do this, but there is a finite amount of numbers a person can recognize. A machine on the other hand, can be tasked with repeating the same boring task billions of times, without any rest or vacations. The machine will never get bored, ask for a raise or call in sick...

 

smile robot

Are there any applications to this?

You could train a model to understand letters. Here are a couple of examples of what can be achieved by scanning a picture with handwritten text:

  • Shipping companies can understand handwritten address in packages
  • Documents can be scanned to get digital versions of them
  • Sales people can scan business cards
  • The blind could "hear" written texts
  • etc

Going beyond numbers and text

Numbers and letters are just human inventions. The potential of training a machine to distinguish patterns in images can be applied to virtually anything in the world. One creative application of this is autonomous driving.

 

autonomous driving

In this specific case, the idea is to put a camera on a car and take images of the road every second. When training the model, for each given image, the correct "answer" will be the position of the wheel at that precise moment.
If the wheel can be steered in 180 degrees, we will train 180 models so that Neural Network can predict the best position of the wheel for any given new image that appears on the camera and to react accordingly. This is actually one of the first ideas behind autonomous driving.

 

We can train a machine to recognize anything !

Ok, so let's get creative here:

  1. What about teaching a model how to recognize your products?
  2. What if we trained a model to recognize your VIP customers faces when they enter your store?
  3. Can you imagine creating a model that is able to sort and classify pieces in an assembly line?
  4. What about teaching police cameras to recognize missing people's faces in the street?

With enough training data, we can take anything in an image (or a video) and teach a Machine how to recognize it.​
The possibilities are endless and the only limit is our imagination.

mind blow

 

MLab, the Machine Learning specialists at your service!

If Machine Learning inspires you and you think you would like to implement a use case in your organisation, please get in touch with us. We are vendor agnostic and we will recommend and integrate the technology that adapts the best to your needs. If available technologies don't satisfy your needs, we can always train a custom model tailored to your project.

Neural Networks

Comments

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Sat, 10/20/2018 - 16:41

Permalink

free vegas casino games <a href="https://casinogameslist.icu/">hypercasinos</a&gt; lady luck casino free games <a href=" https://casinogameslist.icu/ ">big slots games for free</a> | [url=https://casinogameslist.icu/]hollywood casino[/url] [url=https://casinogameslist.icu/]play free win real cash[/url]

First name
NeenseCamma
Last name
NeenseCammaLK
Email
amvoitalsObtaila@villarrealmail.men

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Sat, 10/20/2018 - 21:35

Permalink

cbd cream for pain relief <a href="https://cbdonline2018.com/">retail stores selling cbd oil</a> cbd dog treats <a href=" https://cbdonline2018.com/ ">cbd side effects on liver</a> | https://cbdonline2018.com/ - cbd oil in canada https://cbdonline2018.com/ - where can you buy cbd oil

First name
Pruffistarbub
Last name
PruffistarbubNM
Email
howvdtalsObtaila@maldonadomail.men

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Sun, 10/21/2018 - 01:13

Permalink

absolutely free slots <a href="https://onlinecasinorealmoney.icu/">doubledown casino bonus collector</a> casino bonus codes <a href=" https://onlinecasinorealmoney.icu/ ">zone online casino</a> | https://onlinecasinorealmoney.icu/ - online casino bonus https://onlinecasinorealmoney.icu/ - borgata online casino

First name
Embatly
Last name
EmbatlyWP
Email
avyadtalsObtaila@berrymail.men

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Sun, 10/21/2018 - 01:34

Permalink

real casino <a href="https://playcasinovegas.icu/">win free money no deposit</a> online casino games free <a href=" https://playcasinovegas.icu/ ">caesar casino online slot games</a> | https://playcasinovegas.icu/ - casino games free slots https://playcasinovegas.icu/ - casino games free online

First name
hatulump
Last name
hatulumpPW
Email
uyvqatalsObtaila@americainsurance2018.top

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Sun, 10/21/2018 - 14:32

Permalink

online casino games <a href="https://casinogamesplay.icu/">all free casino slots</a> play slots for real money <a href=" https://casinogamesplay.icu/ ">free casino</a> | https://casinogamesplay.icu/ - virgin casino online https://casinogamesplay.icu/ - download free casino slot games

First name
Goomamugunmague
Last name
GoomamugunmagueMT
Email
xfzrxAnydayArerrarve@blakemail.men

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Sun, 10/21/2018 - 18:30

Permalink

casino online slots <a href="https://casinogamesplay.icu/">free casino games slot machines</a> bovada casino <a href=" https://casinogamesplay.icu/ ">free casino slots bonus games</a> | https://casinogamesplay.icu/ - free online casino https://casinogamesplay.icu/ - fortune bay casino

First name
Goomamugunmague
Last name
GoomamugunmagueMT
Email
mjaezAnydayArerrarve@blakemail.men

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Sun, 10/21/2018 - 22:11

Permalink

slot games with bonus spins <a href="https://vegascasinogames.icu/">free casino games for fun</a> play online casino games <a href=" https://vegascasinogames.icu/ ">gsn casino</a> | https://vegascasinogames.icu/ - 888 casino online https://vegascasinogames.icu/ - grand falls casino

First name
orderve
Last name
orderveNR
Email
nytlmtalsObtaila@avinsurance2018.top

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Mon, 10/22/2018 - 03:43

Permalink

hollywood casino free online games <a href="https://mycasinogames.icu/">absolutely free casino slots games</a> bonus casino <a href=" https://mycasinogames.icu/ ">all games list free slots</a> | https://mycasinogames.icu/ - best casino slot games https://mycasinogames.icu/ - play casino

First name
abemeliemHilm
Last name
abemeliemHilmYZ
Email
uwpnstalsObtaila@tezzmail.host

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Mon, 10/22/2018 - 04:37

Permalink

dakota sioux casino <a href="https://online-casino-games.ooo/">free casino games</a> best free slots no download <a href=" https://online-casino-games.ooo/ ">free slots no registration</a> | https://online-casino-games.ooo/ - play online casino https://online-casino-games.ooo/ - online casino games free

First name
soxPlopsFupaquaM
Last name
soxPlopsFupaquaMQL
Email
gwvrqtalsObtaila@goodymail.men

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Mon, 10/22/2018 - 15:51

Permalink

vegas casino slots <a href="https://casino-play.ooo/">100 most popular free slots</a> gsn casino slots <a href=" https://casino-play.ooo/ ">absolutely free casino slots games</a> | https://casino-play.ooo/ - casino slot https://casino-play.ooo/ - 300 free slots no download

First name
alarkagrinsWanda
Last name
alarkagrinsWandaBH
Email
nsqtetalsObtaila@yatesmail.men

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Tue, 10/23/2018 - 01:20

Permalink

caesar casino online slot games <a href="https://instantcasinoplay.icu/">free online casino</a> no deposit bonus codes for usa players <a href=" https://instantcasinoplay.icu/ ">free casino slot games</a> | https://instantcasinoplay.icu/ - google free casino slot games https://instantcasinoplay.icu/ - most popular free casino slots

First name
Phywhelve
Last name
PhywhelveRP
Email
gbsostalsObtaila@aunsurance2018.top

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Tue, 10/23/2018 - 05:00

Permalink

play free slot machines with bonus spins <a href="https://casino-vegas.ooo/">free blackjack vegas world</a> 300 free slots of vegas <a href=" https://casino-vegas.ooo/ ">three rivers casino</a> | https://casino-vegas.ooo/ - online casino https://casino-vegas.ooo/ - casino slot machine games

First name
FraniHamAssumma
Last name
FraniHamAssummaNF
Email
zxzxbtalsObtaila@ramseymail.men

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Sat, 10/27/2018 - 05:56

Permalink

slots for real money <a href="https://onlinecasinoplay.us.org/">free online casino slots</a> | <a href=" https://onlinecasinoplay.us.org/ ">free vegas casino games</a> | <a href=https://onlinecasinoplay.us.org/>online casinos</a> <a href=https://onlinecasinoplay.us.org/>free casino games slotomania</a>

First name
Pruffistarbub
Last name
PruffistarbubNM
Email
qycjztalsObtaila@maldonadomail.men

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Sat, 10/27/2018 - 09:18

Permalink

online casino real money <a href="https://onlinecasinoplay.us.org/">mgm online casino</a> | <a href=" https://onlinecasinoplay.us.org/ ">play free vegas casino games</a> | <a href=https://onlinecasinoplay.us.org/>play casino</a> <a href=https://onlinecasinoplay.us.org/>zone online casino</a>

First name
Pruffistarbub
Last name
PruffistarbubNM
Email
mgnfctalsObtaila@maldonadomail.men

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Thu, 11/01/2018 - 09:54

Permalink

online gambling casino <a href="https://slotsonline.ooo/">vegas world casino games</a> | <a href=" https://slotsonline.ooo/ ">free online casino</a> | <a href=https://slotsonline.ooo/>free casino games no download</a> <a href=https://slotsonline.ooo/>slots games free</a>

First name
NeenseCamma
Last name
NeenseCammaLK
Email
lkxlotalsObtaila@villarrealmail.men

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Thu, 11/01/2018 - 10:23

Permalink

free casino slot games <a href="https://freeonlinecasino.icu/">online casinos for us players</a> | <a href=" https://freeonlinecasino.icu/ ">slot games</a> | <a href="https://freeonlinecasino.icu/">vegas slots online</a> <a href="https://freeonlinecasino.icu/">brian christopher slots</a>

First name
Optiori
Last name
OptioriEQ
Email
frgabtalsObtaila@hollandmail.men

Member for

48 years 11 months

Submitted by Anonymous (not verified) on Thu, 11/01/2018 - 10:25

Permalink

free casino slot games <a href="https://freeonlinecasino.icu/">online casinos for us players</a> | <a href=" https://freeonlinecasino.icu/ ">slot games</a> | <a href="https://freeonlinecasino.icu/">vegas slots online</a> <a href="https://freeonlinecasino.icu/">brian christopher slots</a>

First name
Optiori
Last name
OptioriEQ
Email
cddsjtalsObtaila@hollandmail.men

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.