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.
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:
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:
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.