0

Does anyone know why my code is visualizing the feature maps in grayscale when I’m using it during validation forward-pass?

The output its like below:

enter image description here

And I'm expecting something like below (I mean not grayscale) but don't know-how:

enter image description here

This is my code

def vis_tensor(data):
    data  =data.data.cpu().numpy()
    data =data[0].transpose((1, 2, 0))
    data = data - data.min()
    data = data / data.max()
    data = data * 255
    mean = np.repeat(data.mean(-1, keepdims=True),3 ,2)
    mean = mean.astype('uint8')
    pylab.imshow(mean)
    pylab.savefig('mean.png')
    max = np.repeat(data.max(-1, keepdims=True), 3, 2)
    max = max.astype('uint8')
    pylab.imshow(max, cmap='plasma')
    pylab.savefig('max.png')
Y0shimitsu
  • 171
  • 1
  • 2
  • 9
  • Have you used autoencoder while preparing your training and test dataset? – think-maths Nov 19 '19 at 15:16
  • Can you try removing the `np,repeat(...` lines? I think you are creating pixels with three times the same color value (like rgb 128,128,128) which always yields a shade of grey. Remove that and I think it will work as long as you set the right cmap. – Anton Nov 19 '19 at 15:24
  • Hey @Anton, I have removed the line you said but I'm facing Invalid dimensions for image data error! any idea? – Y0shimitsu Nov 19 '19 at 17:14
  • 1
    Yes, pylab is expecting 3 rgb values per pixel. Try plotting your data with matplotlib's [heatmap](https://stackoverflow.com/questions/33282368/plotting-a-2d-heatmap-with-matplotlib), that will also allow you to easily change the colors. – Anton Nov 19 '19 at 17:19

0 Answers0