The CIFAR dataset can be verified by plotting the images present in the dataset on the console. Since the CIFAR labels are arrays, an extra index would be needed. The ‘imshow’ method from the ‘matplotlib’ library is used to display the image.
We are using the Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code over the browser and requires zero configuration and free access to GPUs (Graphical Processing Units). Colaboratory has been built on top of Jupyter Notebook.
print("Verifying the data") plt.figure(figsize=(10,10)) print("Plot the first 15 images") print("An extra index is needed since CIFAR labels are arrays") for i in range(15): plt.subplot(5,5,i+1) plt.xticks() plt.yticks() plt.grid(False) plt.imshow(train_images[i], cmap=plt.cm.binary) plt.xlabel(class_names[train_labels[i]]) plt.show()
Code credit: https://www.tensorflow.org/tutorials/images/cnn
Verifying the data Plot the first 15 images An extra index is needed since CIFAR labels are arrays