Day 67(DL) — Implementation of an Image Classifier using ConvNets

We’ll use the popular Street View Housing Number dataset for implementing convolutional neural networks using Keras. The objective is to identify the number present in each image. SVHN dataset has almost 60,000 real-world digital images that are labelled. They are real house numbers obtained from Google Street View images. The dataset is freely available online(in different formats) that can be readily used. For this post, ‘.h5’ format has been considered.

Load the training, testing and validation dataset in the respective file names.

Once the information is loaded, the opened file can be closed.

Let’s check the format of the file and the number of records present in train, test and validation.

It would be nice if we visualize the image and check out the details present.

One of the important point to be considered in Convolution nets is the input shape. It should always be in 3D tensors in contrast to a single vector fed into a simple neural network.

Likewise, we can also convert the label encoded output to the one-hot encoded.

Implementation1(Using a simple Convolutional Neural Nets): The filter used will be of size 32X32 with three channels. The simple CNN does not include any max-pooling layer after the convolution layer. To speed up the learning process, the ‘adam’ optimizer has been included.

When we evaluate the simple model on test data, the accuracy came around 82%.

Let’s increase the layers to see whether there is any improvement in the accuracy score. In addition to that, we’ll also employ BatchNormalization, MaxPooling and dropout layers in the model.

Compile the model and execute it.

Let’s validate whether there is any improvement in the accuracy results.

We can visualize and display the images along with the corresponding labels.

We can observe the number ‘8’ has been correctly predicted.

The entire code can be found in the GitHub repository.

Recommended Reading:

AI Enthusiast | Blogger✍