24.07.2016 Views

www.allitebooks.com

Learning%20Data%20Mining%20with%20Python

Learning%20Data%20Mining%20with%20Python

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Classifying Objects in Images Using Deep Learning<br />

The image array is a NumPy array with 3,072 entries, from 0 to 255. Each value is the<br />

red, green, or blue intensity at a specific location in the image.<br />

The images are in a different format than what matplotlib usually uses (to display<br />

images), so to show the image we first need to reshape the array and rotate the<br />

matrix. This doesn't matter so much to train our neural network (we will define<br />

our network in a way that fits with the data), but we do need to convert it for<br />

matplotlib's sake:<br />

image = image.reshape((32,32, 3), order='F')<br />

import numpy as np<br />

image = np.rot90(image, -1)<br />

Now we can show the image using matplotlib:<br />

%matplotlib inline<br />

from matplotlib import pyplot as plt<br />

plt.imshow(image)<br />

The resulting image, a boat, is displayed:<br />

The resolution on this image is quite poor—it is only 32 pixels wide and 32 pixels<br />

high. Despite that, most people will look at the image and see a boat. Can we get a<br />

<strong>com</strong>puter to do the same?<br />

[ 244 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!