class_docstr: Implements the gradient penalty loss term for WGANs.
class_docstr_tok: ["Implements","the","gradient","penalty","loss","term","for","WGANs","."]
code: def call(self, inputs, conditional_inputs):
      with tf.GradientTape() as tape:
          for layer in inputs:
              tape.watch(layer)
          output = self.discriminator(
              _list_or_tensor(inputs + conditional_inputs)
          )
      gradients = tape.gradient(output, inputs)
      gradients = [g for g in gradients if g is not None]
      if len(gradients) > 0:
          norm2 = 0.0
          for g in gradients:
              g2 = tf.square(g)
              dims = len(g.shape)
              if dims > 1:
                  g2 = tf.reduce_sum(g2, axis=list(range(1, dims)))
              norm2 += g2
          penalty = tf.square(tf.sqrt(norm2) - 1.0)
          penalty = self.gan.gradient_penalty * tf.reduce_mean(penalty)
      else:
          penalty = 0.0
      return [output, penalty]
  
imports: from deepchem.models import KerasModel, layers
  from tensorflow.keras.layers import Input, Lambda, Layer, Softmax, Reshape, Multiply
  import numpy
  import tensorflow
  import time
label_desc: Use image node_id 2 for calling the GradientPenaltyLayer obj's underlying member method code with example usage: obj.call(inputs, conditional_inputs) and returns: list