keras-dcgan
keras-dcgan copied to clipboard
127.5
hi,what's the use of 127.5 in this code: X_train = (X_train.astype(np.float32) - 127.5)/127.5
to scale the input datas? If yes ,than how do you calculate 127.5 , is it just match minist data?
127.5 is half of 255, but why?
@lixiang-ucas The purpose of doing so is to normalize and scale the pixel data. You can read more about it here.
The activation function of the output layer of the generator is tanh, which returns a value between -1 and 1. To scale that to 0 and 255 (which are the values you expect for an image), we have to multiply it by 127.5 (so that -1 becomes -127.5, and 1 becomes 127.5), and then add 127.5 (so that -127.5 becomes 0, and 127.5 becomes 255). We then have to do the inverse of this when feeding an image into the discriminator (which will expect a value between -1 and 1).