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

Problem: Face image generation with StyleGAN generates darker and darker output.

Open notnot opened this issue 3 years ago • 6 comments
trafficstars

Problem: Face image generation with StyleGAN generates darker and darker output. I am running the stylegan.py example, doing a training, and the more steps_per_epochs i use, the darker the output becomes, For instance, with steps_per_epoch = 2048, all the output is black. Something is wrong. I did not change anything in the example code except increasing steps_per_epoch in the given train() function.

The output that is generated by loading the pre-trained model is ok, as shown on https://keras.io/examples/generative/stylegan/

notnot avatar Mar 13 '22 20:03 notnot

I found the bug in stylegan.py: The input images are 'normalized' twice, so that they become very dark.

The first normalization is done here:

ds_train = ds_train.map(lambda x: x / 255.0)

the second (in resize_image) by this:

image = tf.cast(image, tf.float32)/127.5 - 1.

The latter one is correct, and should be the only normalization step. Delete the ' ds_train = ds_train.map(lambda x: x / 255.0)' line to fix the bug. Interestingly, the GAN was working, but unexpectedly learning to output very very dark images ;)

notnot avatar Mar 13 '22 21:03 notnot

they never answer in here bro :/

BernardoOlisan avatar Mar 14 '22 03:03 BernardoOlisan

Hey! Would you mind tagging the original author? Usually they are the best first resource to contact for fixing the tutorial. If now, tag me again and we can get the fix included

LukeWood avatar Jun 02 '22 15:06 LukeWood

@LukeWood @fchollet @yarri-oss Please integrate the StyleGAN bug fix mentioned above.

notnot avatar Jun 02 '22 18:06 notnot

LGTM but would ask @soon-yau to confirm as well because I'm not sure I tested agains the correct public version of Celeb A

yarri-oss avatar Jun 02 '22 22:06 yarri-oss

@yarri-oss the "ds_train = ds_train.map(lambda x: x / 255.0)" was wrongly inserted in your last commit. You can create a PR to remove it.

soon-yau avatar Jun 05 '22 10:06 soon-yau