Simple digits recognition with convolutional neural network on JavaScript

CNN Image recognition

In previous article – we learned how to deal with basic deep neural networks to recognize simple digits symbols.

This time we take a look on convolutional neural networks(CNN) doing the same task also using TensorflowJs.

Code on Github at the same place –

CNN – is a special type of DNN which is used exactly for image processing.

Very generally and simplified the difference is that we train our network not on raw input data but on it convolutions with some filters which is done to detect some common features of images and train our model based on that.

The tech stack is basically the same, server part was expanded by CNN functionality as well as client side, but I also used SvelteKit instead of raw Svelte and Vite just to give it a try, you can find this updated version in “client-sk” directory.

All functionality is the same just couple more buttons for CNN network.

CNN application home page

With “Predict all” button we can see results of predictions and probabilities for both networks at the same time witch is pretty cool to compare.

Comparing training stats we can see better results for CNN with bigger dataset images 28×28 comparing to 12×12 for DNN, having same numbers of epochs and training execution time.

DNN loss stats
CNN loss stats

The structure of the CNN model was taken directly from official TFJS tutorial – just trained with our own dataset.

CNN code part1
CNN code part2

If you are completely new to CNN there are good links for learning the basics: – Convolutional Neural Networks Explained – Convolutional Neural Networks Explained (CNN Visualized) – How Convolution Works – A friendly introduction to Convolutional Neural Networks and Image Recognition – How Convolutional Neural Networks work – How convolutional neural networks work, in depth – How to Design a Convolutional Neural Network

Good fundamental in depth text article – CS231n: Convolutional Neural Networks for Visual Recognition.

Another practical example – Image Classification With TensorFlow.js.

Leave a comment

Your email address will not be published. Required fields are marked *