CNN MNIST dataset exercise

Hi Team,

I’m trying to plot MNIST dataset image but it showing error to me. On loading MNIST datsets in 4 batch sizes, printing images.shape is giving me --→ torch.Size([4, 1, 28, 28]).

Channel is 1 as it’s not colored image. While plotting it’s showing ‘Invalid Shape’.

I tried squeezing it using -→ npimg = npimg.squeeze(axis=0) --→ still it showing error as ‘ValueError: cannot select an axis to squeeze out which has size not equal to one’.

I want to know how can I plot these images? and how can i see all the images?



Hi @shweta_s,
Can you try reshaping the image from (x,y,1) to (x,y)
I think it will work, due to the reason:
plt.imshow() takes either a 2D Grayscale image, or a 3D image where Dim3 must be 3(in case of RGB) or 4(in case of RGBA).
Let me know if it doesn’t help.