I was lookking for GAN code in Github. The code I found uses pytorch. In this code, we first normalized the image to mean = 0.5, std = 0.5. Normally, normalize to min = 0 and max = 1. Or normal distribution with mean = 0 and std = 1. Why is this normalized to mean = 0.5 and std = 0.5?
transformtransfo = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))
])
The values of mean
and std
for transform.normalize
are not the desired mean and std, but rather the values to subtract and divide by, i.e., the estimated mean and std.
In your example you subtract 0.5 and then divide by 0.5 yielding an image with mean zero and values in range [-1, 1]
Adding to answer by Shai,
Similar to training other neural networks, we normalize GAN inputs to (1) improve convergence of the nets, and (2) giving an equal range of value to all features so to not make some features dominate others because of wide range of value.
Also, generator in most GAN models tend to use tanh function as final activation, which maps output to [-1, 1] value range. Scaling our image data to the same value range will give equal data for discriminator to be trained upon
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With