LookupError: No gradient defined for operation type: ResizeNearestNeighborGrad

Viewed 2471

I am trying to add Wasserstein gradient penalty into loss calculation of discriminator. Without adding this penalty everything works fine. But when this part is being added, It gives an error something similar to this:

      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)

Here is the part of the source code which is used to calculate Wasserstein gradient penalty:

    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

But it throw above mentioned error when below line is bening executing.

   d_optim = opt_discriminator_step.minimize(total_loss_discriminator, var_list=d_vars)

Still, I have a no clue how to get on with this issue. Any comments or answers are welcome.

0 Answers
Related