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])
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
You must set the color map.
plt.imshow(IMG, cmap='gray')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With