How to save image?

Are you trying to save an image from a tensor? if yes, then you need to specifiy the correct index.

e.g.

tensor1 has shape [64,3,28,28]

then to get one/first image out of it (the batch of 64), you need

image1_tensor= tensor1[0]

now you need to swap the axis to convert it into numpy

image1_numpy = image1_tensor.numpy()

Now if you save image1_numpy, you will get one image.

1 Like