How can Tensorflow and Python be used to verify the CIFAR dataset?


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.

Read More: What is TensorFlow and how Keras work with TensorFlow to create Neural Networks?

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][0]])
plt.show()

Code credit: https://www.tensorflow.org/tutorials/images/cnn

Output

Verifying the data
Plot the first 15 images
An extra index is needed since CIFAR labels are arrays

Explanation

  • The data which is normalized, is visualized.
  • This is done using the 'matplotlib' library.

Updated on: 20-Feb-2021

64 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements