2

我正在尝试将Wasserstein 梯度惩罚添加到鉴别器的损失计算中。如果不添加此惩罚,一切正常。但是当这部分被添加时,它会给出一个类似这样的错误:

      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)

不过,我不知道如何处理这个问题。欢迎任何意见或答案。

4

0 回答 0