How to do it...

Perform the following steps:

  1. We'll start by loading the necessary libraries to download, unzip, and save CIFAR-10 images:
import os 
import tarfile 
import _pickle as cPickle 
import numpy as np 
import urllib.request 
import scipy.miscfrom imageio import imwrite
  1. We now declare the CIFAR-10 data link and create the temporary directory we will store the data in. We'll also declare the ten categories to reference when saving the images later on:
cifar_link = 'https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz' 
data_dir = 'temp' 
if not os.path.isdir(data_dir): 
    os.makedirs(data_dir) 
objects = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'] 
  1. Now we'll download the CIFAR-10 .tar data ...

Get TensorFlow Machine Learning Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.