Save normalized tensor to png in a loop

Hi there,
I am working on a GAN and cannot make it work to save images that I transformed into tensors back to “normal” pngs within a loop. The same goes for the tensors that are generated by the Generator.

I applied the following transformation for the original images I am using for the training in the GAN ( I hope i did it the right way):

transform = transforms.Compose(
transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5]),

When trying to save the tensors as png images in a loop with the following code they do not come out the right way:

real_samples = next(iter(train_loader))
for i in range(4):
torchvision.utils.save_image(real_samples[i, :, :, :],

On the left is an example of the original image after transformation and on the right an example of the “wrongly” saved ones:

Can anyone please help me out with saving the images in the right way?

So I just found the solution, which might be obvious to all of you but me. :smiley: I had to normalize the images again. I thought i had to do the opposite (de-normalize). Accordingly, the code for saving the images is

real_samples[i, :, :, :], ‘Training_Punks/Training_{}.png’.format(i), normalize=True)

Can someone let me know why I need to normalize them again?