title: Tensorflow RandomContrast Layer Error "LookupError: gradient registry has no entry for: AdjustContrastv2"
body: <p>I get the following error when using <code>tf.keras.layers.RandomContrast(...)</code> on tensorflow 2.7.0</p>
  <pre><code>    File &quot;/tmp/ipykernel_69350/2836335801.py&quot;, line 16, in train_step  *
          gradients_of_generator = gen_tape.gradient(gen_loss, generator.trainable_variables)
  
      LookupError: gradient registry has no entry for: AdjustContrastv2
  </code></pre>
  <p>Do I have to define a custom gradient registry as a workaround, or is there a more direct solution to this problem?</p>
  <p>Here's the model section:</p>
  <pre class="lang-py prettyprint-override"><code>def make_discriminator_model():
      model = tf.keras.Sequential()
      model.add(tf.keras.layers.RandomFlip(&quot;horizontal&quot;))
      model.add(layers.Rescaling(scale=2, offset=-1))
      model.add(tf.keras.layers.RandomRotation(0.2))
      model.add(tf.keras.layers.RandomZoom(0.15))
      model.add(tf.keras.layers.RandomTranslation(0.12,0.12))
      model.add(tf.keras.layers.RandomContrast(0.2))
      model.add(tf.keras.layers.Resizing(50,50))
      
      model.add(layers.Conv2D(64,(5,5),strides=(2, 2),padding='same'))
      model.add(layers.LeakyReLU())
      model.add(layers.BatchNormalization())
      model.add(layers.SpatialDropout2D(0.2))
  
      ...
  </code></pre>
  <p>And here's the inner method in the training loop</p>
  <pre class="lang-py prettyprint-override"><code>@tf.function
  def train_step(images):
      noise = tf.random.normal(noise_dim)
  
      with tf.GradientTape() as gen_tape, tf.GradientTape() as disc_tape:
        generated_images = generator(noise, training=True)
  
        real_output = discriminator(images, training=True)
        fake_output = discriminator(generated_images, training=True)
  
        gen_loss = generator_loss(fake_output)
        disc_loss = discriminator_loss(real_output, fake_output)
  
      gradients_of_generator = gen_tape.gradient(gen_loss, generator.trainable_variables)
      gradients_of_discriminator = disc_tape.gradient(disc_loss, discriminator.trainable_variables)
  
      generator_optimizer.apply_gradients(zip(gradients_of_generator, generator.trainable_variables))
      discriminator_optimizer.apply_gradients(zip(gradients_of_discriminator, discriminator.trainable_variables))
      
      return generated_images
  </code></pre>
  <p>Generator Model:</p>
  <pre class="lang-py prettyprint-override"><code>def make_generator_model():
      model = tf.keras.Sequential()
  
      model.add(layers.Dense(24*24*4, input_shape=[in_shape]))
      model.add(layers.LeakyReLU())
      model.add(layers.BatchNormalization())
      
      model.add(layers.Reshape((24,24,4)))
  
      model.add(layers.Conv2DTranspose(16, (8,8), strides=(2, 2), padding='same', use_bias=False))
      model.add(layers.LeakyReLU())
      model.add(layers.BatchNormalization())
  
      ...
      
      model.add(layers.Conv2DTranspose(3, (8,8), strides=(4, 4), padding='same', use_bias=False, activation='tanh'))
      model.add(layers.Rescaling(scale=.5, offset=.5))
      
      return model
  </code></pre>
  <p>If I remove the RandomContrast layer, everything works fine.</p>