Practical Computer Vision
上QQ阅读APP看书,第一时间看更新

CIFAR-10

Though MNIST is one of the easiest datasets to get started, the lack of color images makes it less appealing for tasks that require a colored dataset. A slight more complex dataset is CIFAR-10 by Alex and others[1], which consists of 10 categories of images with 60,000 training images and 10,000 test images, uniformly from each category. The size of each image is 32 x 32 and each has three color channels. This dataset can also be easily loaded in Keras, as follows:

from __future__ import print_function

from keras.datasets import cifar10
import matplotlib.pyplot as plt

# Download and load dataset
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
labels = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']
# to know the size of data
print("Train data shape:", x_train.shape, "Test data shape:", x_test.shape)

# plot sample image
idx = 1500
print("Label:",labels[y_train[idx][0]])
plt.imshow(x_train[idx])
plt.axis('off')
plt.show()

The labels, in order, are: airplane, automobile, bird, cat, deer, dog, frog, horse, ship, and truck.