fchollet / deep-learning-with-python-notebooks

Jupyter notebooks for the code samples of the book "Deep Learning with Python"
MIT License
18.17k stars 8.53k forks source link

In the GAN notebook, generated images have the undesired effect of #112

Open phunc20 opened 5 years ago

phunc20 commented 5 years ago

bright, single-colored pots. I happened to realize that it is not entirely due to GAN itself (if at all), but to the way we convert it to PIL images and plot it afterwards. This is due to the fact that the final layer of the generator model uses tanh activation, which results in neuron output in the range of [-1, 1], unlike real_images, which are in [0, 1]. So I find it best to leave, for the lines of code involving image.array_to_img() [I believe there are only three], leave real_images part unchanged, and modify generated_images part to sth like: image.array_to_img(generated_images[i], scale=True). This will remove the above-mentioned undesired effect.

The reason is that the [-1, 0] part of [-1, 1] when multiplied by 255 and then converted to unit8 will have unexpected color behaviour. (The negative values will circle periodically back like in Z_256)

Actually, the training process and hyperparameters of the optimizers can also be altered accordingly if we have the generator output's range be consistent with the real images range and train.