Backtransforming a PyTorch Tensor
I have trained a WGAN on the CelebA dataset in PyTorch following this youtube video. Since I do this on Google Cloud Platform where TensorBoard is not availabe, I save one figure of generated images by the GAN every epoch to see how the GAN is actually doing.
Now, the saved pdf files look sth like this: generated images. Unfortunately, this is not really readable, and I suspect this has to do with the preprocessing I do:
trafo = transforms.Compose(
                    [transforms.Resize(size = (64, 64)),
                    transforms.ToTensor(), 
                    transforms.Normalize( mean = (0.5,), std = (0.5,))]) 

Is there any way to kind of undo this transformation when I save the image?
Currently, I save the image every epoch as follows:
visualization = torchvision.utils.make_grid(
                           tensor = gen(fixed_noise), 
                           nrow = 8, 
                           normalize = False)
plt.savefig(&quot;generated_WGAN_&quot; + datetime.now().strftime(&quot;%Y%m%d-%H%M%S&quot;) + &quot;.pdf&quot;)

Also, I should probably mention that in the Jupyter notebook, I get the following warning:
&quot;Clipping input data to the valid range for imshow with RGB data ([0..1]) for floats or [0..255] for integers).&quot;

It seems like your output pixel values are in range [-1, 1] (please verify this).
Therefore, when you save the images, the negative part is being clipped (as the error message you got suggests).
Try:
visualization = torchvision.utils.make_grid(
                           tensor = torch.clamp(gen(fixed_noise), -1, 1) * 0.5 + 0.5,  # from [-1, 1] -&gt; [0, 1]
                           nrow = 8, 
                           normalize = False)
plt.savefig(&quot;generated_WGAN_&quot; + datetime.now().strftime(&quot;%Y%m%d-%H%M%S&quot;) + &quot;.pdf&quot;)

