Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing image from fashion_MNIST data gives colored image?

The well-known fashion_MNIST data set for deep leanring/computer vision is a collection of greyscale images[https://github.com/zalandoresearch/fashion-mnist].

This dataset is already available with keras [https://keras.io/datasets].

However, when I loaded the data set in Tensorflow Keras API and tried to print some image. I got colored images. I wonder why? Can anyone please explain. Here's my code:

import tensorflow as tf
mnist = tf.keras.datasets.fashion_mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()

import matplotlib.pyplot as plt
plt.imshow(training_images[0])
#print(training_labels[0])
#print(training_images[0])
like image 746
Dr Nisha Arora Avatar asked Oct 20 '25 23:10

Dr Nisha Arora


2 Answers

It happens because of imshow() method of matplotlib. By default, it uses rcParams["image.cmap"] to 'viridis' due to which we got a colored image. You can see here https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.pyplot.imshow.html. You can also check these parameters in your terminal by running this code:

 import matplotlib.pyplot as plt
 print(plt.rcParams)

If we set it to "Greys" then we will get grey image. You can set it by running this code:

plt.rcParams['image.cmap'] = 'Greys'

You can read more about 'viridis' here: https://matplotlib.org/3.1.1/tutorials/colors/colormaps.html

like image 53
Abhishek Avatar answered Oct 22 '25 14:10

Abhishek


You must set the color map.

plt.imshow(IMG, cmap='gray')
like image 39
abhilb Avatar answered Oct 22 '25 15:10

abhilb



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!