DeepLearningImplementations icon indicating copy to clipboard operation
DeepLearningImplementations copied to clipboard

tf.sqrt in WGAN-GP gradient penalty formula throws NaNs

Open Imperssonator opened this issue 7 years ago • 2 comments

I've found in training on my own image dataset that I get an InvalidArgumentError: Nan in summary histogram. This was caused by the following line:

slopes = tf.sqrt(tf.reduce_sum(tf.square(grad_D_X_hat), reduction_indices=red_idx))

You'd think that the sum of squared values would never give anything less than 0, but apparently it does, because adding 1e-8 inside the sqrt() fixed the problem:

slopes = tf.sqrt( 1e-8 + tf.reduce_sum(tf.square(grad_D_X_hat), reduction_indices=red_idx))

Imperssonator avatar Mar 09 '18 03:03 Imperssonator

I faced the same problem while training mnist with WGANGP, this solutions works fine for me. Thanks~

chunhanl avatar Mar 30 '18 02:03 chunhanl

@Imperssonator faced the same problem too, that's a werid problem, thanks for saved my life!

hujinsen avatar Jun 02 '18 01:06 hujinsen