taki0112 / StyleGAN-Tensorflow

Simple & Intuitive Tensorflow implementation of StyleGAN (CVPR 2019 Oral)
MIT License
211 stars 60 forks source link

Bug in minibatch_stddev_layer #17

Closed aydao closed 4 years ago

aydao commented 4 years ago

Hello, I believe there is a potential bug in the code for minibatch_stddev_layer. Specifically, in the first call to reshape (currently line 538 in ops.py)

https://github.com/taki0112/StyleGAN-Tensorflow/blob/1cca9da1f55f91a42a4b05b61c9340930eda0d94/ops.py#L538

In your code, you are using the data_format of 'NHWC' while the original nvlabs version uses 'NCHW' for StyleGAN. In the minibatch_stddev_layer function, you appear to have replicated the same code used by nvlabs (which assumes the NCHW format) but neglected to change the array indexes to reflect your use of NHWC. I noticed the indexes in line 547 were changed correctly to reflect your use of NHWC, so I am guessing the fact they are not changed on line 538 might be an oversight.

I believe the correct line of code would be

y = tf.reshape(x, [group_size, -1, num_new_features, s[3] // num_new_features, s[1], s[2]])

Potentially, this bug could explain some of the results that look high quality but a bit "off" compared to Nvidia's version (#7).