我正在尝试将Wasserstein gradient penalty添加到鉴别器的损失计算中。不添加此罚款,一切正常。但是,当添加此部分时,会产生类似于以下内容的错误:
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/gradients_impl.py", line 737, in _GradientsHelper
(op.name, op.type))
LookupError: No gradient defined for operation 'gradients/discriminator/decoder/ResizeNearestNeighbor_grad/ResizeNearestNeighborGrad' (op type: ResizeNearestNeighborGrad)
这是源代码中用于计算Wasserstein梯度罚分的部分:
differences = tf.subtract(images_fake, images_real)
alpha_shape = [params.batch_size] + [1] * (differences.shape.ndims - 1)
alpha = tf.random_uniform(shape=alpha_shape, minval=0., maxval=1.)
interpolates = images_real + (alpha * differences)
d_model = Model(params, args.mode, interpolates, reuse_variables, images_fake, 1)
gradients = tf.gradients(d_model.logistic_linear, [interpolates])[0]
slopes = tf.sqrt(tf.reduce_sum(tf.square(gradients), reduction_indices=[1]))
gradient_penalty = tf.reduce_mean((slopes - 1.) ** 2)
_gradient_penalty = 10 * gradient_penalty
但是当下面的行开始执行时,它抛出上述错误。
d_optim = opt_discriminator_step.minimize(total_loss_discriminator, var_list=d_vars)
仍然,我不知道如何继续处理此问题。欢迎任何评论或答案。