Loading CIFAR

The datasets can be downloaded from the official website mentioned previously in Python, Matlab, and binary versions. There are different ways to load and read these datasets. In practice, within our TensorFlow implementations, we load it using the Keras library (https://keras.io/), which is now a part of TensorFlow in the tf.keras module. Here, we present some example code to load the CIFAR-10 dataset, but the CIFAR-100 dataset could be loaded in much the same way:

import tensorflow as tf 

from tf.keras.datasets import cifar10

(x_train, y_train), (x_test, y_test) = cifar10.load_data() print('x_train shape:',x_train.shape) print('y_train shape:',y_train.shape) print('x_test shape:',x_test.shape) print('y_test shape:',y_test.shape) print('x_train.shape[0]:',training samples) print('x_test.shape[0]:',test samples) # Convert class vectors to binary class matrices y_train = tf.keras.utils.to_categorical(y_train,10) y_test = tf.keras.utils.to_categorical(y_test,10)

This code returns two tuples:

x_train, x_test: uint8 array of RGB image data with shape (num_samples, 3, 32, 32)
y_train, y_test: uint8 array of category labels (integers in range 0-9) with shape (num_samples,)

Output from the preceding code's print statements is as follows:

x_train shape:(50000,32,32,3 

y_train shape:(50000,1) 

x_test shape:(10000,32,32,3) 

y_test shape:(10000,1) 

Similarly, the CIFAR-100 dataset is loaded using the following:

from tf.keras.datasets import cifar100

(x_train, y_train), (x_test, y_test) = cifar100.load_data(label_mode='fine')
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.8.8