This is the most ambitious AI program of the entire set.
This is a
to do character recognition from hand-writing.
Note the video mentions that the theory behind
some things is explained in the "course notes".
These notes (part of an M.Sc. course) are not provided here.
You will have to learn AI theory separately.
This is just a series of AI programming exercises.
Character recogn... Neural network to do character recognition from image database and from handwriting in real-time.
learns from a database of images paired with the correct answer of what character is written in the image.
After a while, it can recognise new images from the database, that it never saw before,
with 95 percent accuracy.
Then it tries to use that knowledge to recognise new handwriting in real time.
You can write characters in the browser and the network will recognise them
with accuracy of maybe 60 percent.
This despite the fact that this network knows literally nothing at the start of the run.
Neural networks are amazing!
This uses the MNIST database
of exemplars (handwritten digits and correct answer)
For testing, the MNIST test set is used.
These are different exemplars to the training exemplars.
Running the program
There are three sections:
Doodle: Draw your own image.
You can draw a "doodle" of a digit
in this area and the network will try to classify it.
Training: This is where training takes place.
The network shows the exemplars it is training on. They flash by.
It also runs an ongoing test of how well it is doing out of 100 percent accurate classification. (It does not display the test exemplars.)
Demo: A random test demo.
Picks a random image and tests if the network can classify it.
These images are not from the training set.
They are from a separate test set. The network has not been trained on these images.
So these are new, unseen before images for the network.
Notes on the code
The images are tiny: 28 x 28 pixels, greyscale
integer values 0 to 255.
We convert these pixels to (28 squared = 784)
neural network input nodes,
taking real number values 0 to 1.
There are 10 output nodes.
They generate output for each character 0 .. 9.
The highest value is our "guess" as to which of the 10 this is.
is edited so it
calls a function randomWeight()
that we define in the World.
Fetching the exemplars
Defining the exemplars
First, JS on a website
cannot read local files on the client.
So the data must be on the Ancient Brain server.
Binary file on Ancient Brain:
Ancient Brain allows the upload of lots of file formats, such as JSON.
The MNIST data is in its own binary format, explained
It does not use any file extension.
Then I realised that I allow file extensions for 3D models that could be re-used to upload any binary data.
An example would be
used for 3D models. You can rename MNIST or other binary data to .bin and it should upload.
Alternatively, convert it to JSON.
Fetching the data from JS
The next issue is JS reading this binary file.
Daniel Shiffman writes a file
to do this.
This uses fetch
to get the files from local server.
This is now edited
to point to the Ancient Brain files
Blurring the doodle
To try to improve doodle recognition,
we made a change to make the doodle more like the MNIST images.
In the original Coding Train code,
the doodle produces sharp images with no blurry edges.
This leads to neural network input nodes which are all either 0 or 1, with no values in between.
But in the MNIST data, pixels are shades of grey
and the neural network inputs end up with real numbers ranging from 0 to 1.
Perhaps we need to make the doodles more like the MNIST images.
The change we made is to "blur" the edges of the doodle using
To see how this changes the input nodes,
we added a debug function
so you can see in the console the exact input nodes for the doodle and for a demo image.
Type this in the console: