Accéder au contenu principal

CNN for handwritten numbers recognition

Build a Convolutional Neural Network for image classification by using Tensorflow library

Image classification is an important task that may be needed in several fields in our daily life, there are many datasets on which machine learning algorithms are applied.

In this article, I'll show a basic program for a constitutional neural network applied on MNIST dataset for handwritten images using Keras.



MNIST dataset Overview


MNIST dataset is composed of 60000 images for the training and 10000 images for training. 

Each image is black and white and has a size of 28x28 pixels.

This image shows some samples.



                                                                Source: Wikipedia


To load the dataset in a Python program, Kears gives a simle command line to do so.

what is a CNN?

CNN's architecture is very simple. It's in the form of convolution layers stacked to fully connected layers. The convolution layers aim to reduce the conditionality of the input data before feeding it to the neural network. 
This idea was first introduced by Yann Lecun who is an artificial intelligence scientist in Facebook. The special thing about CNN is that they are capable of learning the most characterizing features in an image.

                                                                  Source: Wikipedia
In our case, a simple architecture of CNN is used with  two convolution layers followed by maxpooling layers. At last we have two dense layers.


RESULTS

Keep reading, there are some visuals at the end.

LOG:

After 3 epochs of training, we've got this 98% accuracy on the test data. We can achieve better result by parameter tuning.

Train on 48000 samples, validate on 12000 samples
Epoch 1/3
48000/48000 [==============================] - 39s 816us/sample - loss: 0.1872 - accuracy: 0.9445 - val_loss: 0.0820 - val_accuracy: 0.9766
Epoch 2/3
48000/48000 [==============================] - 37s 767us/sample - loss: 0.0635 - accuracy: 0.9800 - val_loss: 0.0740 - val_accuracy: 0.9793
Epoch 3/3
48000/48000 [==============================] - 41s 851us/sample - loss: 0.0418 - accuracy: 0.9864 - val_loss: 0.0523 - val_accuracy: 0.9841

test accuracy: 0.9857



Conclusion

Miraculously, the accuracy is of 98%! And it was achieved with a shallow convolutional neural network. It could be improved by hyper-parameters tuning.

This means that the model is almost always capable of correctly identifying the number in the image.

Connect with me:

Commentaires

Posts les plus consultés de ce blog

Support Vector Machine Explained

Support Vector machines are a very recent technique used for making decision boundaries. This machine learning method has been created by Russian scientists   Vladimir Vapnik  and  Hava Siegelmann  in early 90's. In this article we will see the concept on which support vector machines  and an implementation on Scikit-Learn with Python. Suppose we have a space where we have samples of data points belonging to two classes (Orange and green points in our case) The question is how to divide the orange points from the green points. The first idea of SVM is that we want to draw a straight line. BUT WHICH LINE ? As we see in the last figure, there an infinity of lines that solve the problem. But which one to choose? Well we would like to draw a straight line inside the widest street that separates the orange samples from the green samples. So the approach is to try to put the line inside the street in such a way that the street between the two classes be