Number Predictor using Tensorflow.js and MNIST dataset
I recently starting learning Tensorflow.js to create machine learning models on the browser. It took me a few weeks to learn the API but I finally got something working.
There are two models in this example. One that was already trained locally on my computer and the browser model which is train right on your browser. I was very impressed by the accuracy of the browser trained model. I was able to get about 95% accuracy in some cases. I might create a tutorial but for now here's a link to the demo and source code.
A Convolutional Neural Network (CNN) with 5 layers, 1 input 3 hidden and 1 for output. See code for more on activation function and other info on the model.
- Load the MNIST dataset if training the model in the browser.
- Load the pre-trained model or the browser trained model.
- Take the input from the canvas element and do some processing to the pixels.
- Take the input and run it throw the trained model.
- Take the predictions and determine which one has the higher probability.
- Display the highest predicted number.
Overall I was very impressed by Tensorflow.js and the accuracy I got considering that it was running on the browser. One other thing to mention is that you don't have to train your own model. You can use a pre-trained model for object detection, image caption, and more. The API is very simple to use and learn.