Exploring MNIST dataset

Before we jump on building our awesome neural network, let's first have a look at the famous MNIST dataset. So let's visualize the MNIST dataset.

Words of Wisdom: You must know your data and how it has been pre-processed to know how the models you build perform the way they do. This section reviews the significant work that has been done in preparation of the dataset to make our current job of building the MLP easier. Always remember: Data Science begins with DATA!

Let's start therefore by downloading the data: 

from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("/tmp/data/", one_hot=True)

If we examine the mnist variable content. It is structured in a specific format having 3 major components: TRAIN, TEST, and VALIDATION. Each set has handwritten images and their respective labels. The images are stored in a flattened way as a single vector:

Figure 2.1: Format of MNIST dataset

Let's extract one image from the dataset and plot it. Since the stored shape of a single image matrix is [1,784] which we need to reshape into [28,28] to visualize the original image:

sample_image = mnist.train.images[0].reshape([28,28])

Once we have the image matrix we will use matplotlib to plot it as shown as follows:

import matplotlib.pyplot as plt
plt.gray()
plt.imshow(sample_image)

Output:

Figure 2.2: A sample MNIST dataset 

Similar to this image, there are total 55,000 similar images of handwritten digits [0-9]. The labels in the mnist dataset are the true value of the digit which is present in the image. Our objective then, is to train a model with these set of images and labels so that it can predict the labels of any provided image from mnist dataset.

Be a Deep Learning explorer: If you are interested to play around with the dataset you can try the Colab Notebook here (https://drive.google.com/file/d/1-GVlob72EyiJyQpk8EL2fg2mvzaEayJ_/view?usp=sharing).
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset