In [7]:
import numpy as np
import cPickle
import matplotlib.pyplot as plt
def extractImagesAndLabels(path, file):
f = open(path+file, 'rb')
dict = cPickle.load(f)
images = dict['data']
images = np.reshape(images, (10000, 3, 32, 32))
labels = dict['labels']
return images, labels
def extractCategories(path, file):
f = open(path+file, 'rb')
dict = cPickle.load(f)
return dict['label_names']
images, labels = extractImagesAndLabels("data/CIFAR-10/cifar-10-batches-py/", "test_batch")
categories = extractCategories("data/CIFAR-10/cifar-10-batches-py/", "batches.meta")
def getImage(images, id):
image = images[id]
image = image.transpose([1, 2, 0])
image = image.astype('float32')
image /= 255
return image
imgid=35
image = getImage(images, imgid)
%matplotlib inline
imgplot = plt.imshow(image)
categoryid = labels[imgid]
print(categories[categoryid])
In [8]:
from keras.datasets import cifar10
(X_train, y_train), (X_test, y_test) = cifar10.load_data()
print('X_train shape:', X_train.shape)
print('X_test shape:', X_test.shape)
print(X_test.shape[0], 'testing samples')
image=X_test[0]
image = image.astype('float32')
image /= 255
%matplotlib inline
imgplot = plt.imshow(image)
In [ ]: