keras-dcgan icon indicating copy to clipboard operation
keras-dcgan copied to clipboard

127.5

Open wxy656 opened this issue 7 years ago • 3 comments

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?

wxy656 avatar Mar 27 '17 03:03 wxy656

127.5 is half of 255, but why?

lixiang-ucas avatar May 16 '17 08:05 lixiang-ucas

@lixiang-ucas The purpose of doing so is to normalize and scale the pixel data. You can read more about it here.

liamnaka avatar May 30 '17 22:05 liamnaka

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).

ElectronicChaos avatar Dec 13 '17 02:12 ElectronicChaos