class_docstr: Perform gradients backpropagation for a given input
  
  Paper: [Deep Inside Convolutional Networks: Visualising Image Classification
      Models and Saliency Maps](https://arxiv.org/abs/1312.6034)
class_docstr_tok: ["Perform","gradients","backpropagation","for","a","given","input","Paper",":","[","Deep","Inside","Convolutional","Networks",":","Visualising","Image","Classification","Models","and","Saliency","Maps","]","(","https",":","\/\/arxiv.org\/abs\/1312.6034",")"]
docstr: Compute gradients for target class.
  
  Args:
      images (numpy.ndarray): 4D-Tensor of images with shape (batch_size, H, W, 3)
      model (tf.keras.Model): tf.keras model to inspect
      class_index (int): Index of targeted class
  
  Returns:
      tf.Tensor: 4D-Tensor
docstr_tok: ["Compute","gradients","for","target","class",".","Args",":","images","(","numpy.ndarray",")",":","4D-Tensor","of","images","with","shape","(","batch_size",",","H",",","W",",","3",")","model","(","tf.keras.Model",")",":","tf.keras","model","to","inspect","class_index","(","int",")",":","Index","of","targeted","class","Returns",":","tf.Tensor",":","4D-Tensor"]
code: def compute_gradients(images, model, class_index):
      """
      Compute gradients for target class.
  
      Args:
          images (numpy.ndarray): 4D-Tensor of images with shape (batch_size, H, W, 3)
          model (tf.keras.Model): tf.keras model to inspect
          class_index (int): Index of targeted class
  
      Returns:
          tf.Tensor: 4D-Tensor
      """
      with tf.GradientTape() as tape:
          inputs = tf.cast(images, tf.float32)
          tape.watch(inputs)
          scores = model(inputs)
          scores_for_class = scores[:, class_index]
  
      return tape.gradient(scores_for_class, inputs)
  
file_path: tf-explain/tf_explain/core/vanilla_gradients.py
imports: from warnings import warn
  import tensorflow
  from tf_explain.utils.display import grid_display
  from tf_explain.utils.image import transform_to_normalized_grayscale
  from tf_explain.utils.saver import save_grayscale
label_desc: Use image node_id 5 for calling the VanillaGradients obj's underlying member method code with example usage: obj.compute_gradients(images, model, class_index) and returns: tape