CIFAR10 DatasetΒΆ

This example shows how to download/load/import CIFAR10

6:frog, 9:truck, 9:truck, 4:deer, 1:automobile, 1:automobile, 2:bird, 7:horse, 8:sheep, 3:cat

Out:

        ... cifar-10-python.tar.gz already exists

Loading cifar10:   0%|          | 0/5 [00:00<?, ?it/s]
Loading cifar10:  20%|##        | 1/5 [00:03<00:15,  3.91s/it]
Loading cifar10:  40%|####      | 2/5 [00:05<00:09,  3.14s/it]
Loading cifar10:  60%|######    | 3/5 [00:06<00:04,  2.49s/it]
Loading cifar10:  80%|########  | 4/5 [00:06<00:01,  1.85s/it]
Loading cifar10: 100%|##########| 5/5 [00:07<00:00,  1.68s/it]
Loading cifar10: 100%|##########| 5/5 [00:07<00:00,  1.57s/it]
Dataset cifar10 loaded in8.69s.

import numpy_datasets as nds
import matplotlib.pyplot as plt

cifar10 = nds.images.cifar10.load()

plt.figure(figsize=(10, 4))
for i in range(10):

    plt.subplot(2, 5, 1 + i)

    image = cifar10["train_set/images"][i]
    label = cifar10["train_set/labels"][i]

    plt.imshow(image.transpose((1, 2, 0)) / image.max(), aspect="auto", cmap="Greys")
    plt.xticks([])
    plt.yticks([])
    plt.title("{}:{}".format(label, cifar10["label_to_name"][label]))

plt.tight_layout()

Total running time of the script: ( 0 minutes 9.329 seconds)

Gallery generated by Sphinx-Gallery