MNIST digits

Now, let's learn about MNIST digits. In this section, we'll look at the ImageData notebook that I've prepared to help us understand how to deal with image data; downloading and getting the MNIST digits; looking at images as raw numbers; and then finally, visualizing the actual images based on this numeric data.

The code we're going to be working with is contained in an IPython Notebook. This is the way we've set up our container, so you're going to be running your container like we mentioned at the end of the setting up your Machine Learning Toolkit. I've also prepared an ImageData IPython Notebook that we're going to be working with. We will start off by importing all the necessary packages, and we're going to, turn on Matplotlib in order to automatically plot. This means that when we show an image, we don't have to call .plot; it'll do it for us automatically:

Importing packages

Keras actually has the MNIST digits built-in as a dataset, so we're going to use this convenience and go ahead and load them up.

You need an internet connection because it's going to be downloading these as a file from Amazon S3.

As we load the data, there will be a Python tuple that we're going to be unpacking iPnto two sets: a training set, and a testing set:

Python tuple

It is actually a common convention in machine learning to split your data into segments. You use it in order to see that your model is actually learning with the training set. Then, you can use a testing set to make sure that your model is not overfitting, which is really taking into consideration whether your model is memorizing the training data or whether it's actually learning.

Now, let's look at a quick setting with the format options for NumPy. As we print out arrays, we're looping through the image as an array of arrays, and then printing out the data. As you can see, the image is really just numbers from 0 to 255:

Grey scale image (arrays of array)

This is a grayscale image, and each of these integers here records how dark that particular pixel is.

Now, let's plot the image and see what these numbers really look like. Matplotlib has a simple plot function that you can give an array of arrays, or basically a two-dimensional array of XY pixels, and it'll draw it out as an .image file. Following, you can see what looks an awful lot like a zero:

Plotting image
..................Content has been hidden....................

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