class_docstr: Perform SmoothGrad algorithm for a given input
  
  Paper: [SmoothGrad: removing noise by adding noise](https://arxiv.org/abs/1706.03825)
docstr: Compute average of gradients for target class.
  
  Args:
      noisy_images (tf.Tensor): 4D-Tensor of noisy images with shape
          (batch_size*num_samples, H, W, 3)
      model (tf.keras.Model): tf.keras model to inspect
      class_index (int): Index of targeted class
      num_samples (int): Number of noisy samples to generate for each input image
  
  Returns:
      tf.Tensor: 4D-Tensor with smoothed gradients, with shape (batch_size, H, W, 1)
code: def get_averaged_gradients(
      noisy_images, model, class_index, num_samples
  ):
      """
      Compute average of gradients for target class.
  
      Args:
          noisy_images (tf.Tensor): 4D-Tensor of noisy images with shape
              (batch_size*num_samples, H, W, 3)
          model (tf.keras.Model): tf.keras model to inspect
          class_index (int): Index of targeted class
          num_samples (int): Number of noisy samples to generate for each input image
  
      Returns:
          tf.Tensor: 4D-Tensor with smoothed gradients, with shape (batch_size, H, W, 1)
      """
      num_classes = model.output.shape[1]
  
      expected_output = tf.one_hot(
          [class_index] * noisy_images.shape[0],
          num_classes,
          on_value=None,
          off_value=None,
      )
  
      with tf.GradientTape() as tape:
          inputs = tf.cast(noisy_images, tf.float32)
          tape.watch(inputs)
          predictions = model(inputs)
          loss = tf.keras.losses.categorical_crossentropy(
              expected_output, predictions
          )
  
      grads = tape.gradient(loss, inputs)
  
      grads_per_image = tf.reshape(
          grads, (-1, num_samples, *grads.shape[1:])
      )
      averaged_grads = tf.reduce_mean(grads_per_image, axis=1)
  
      return averaged_grads
  
file_path: tf-explain/tf_explain/core/smoothgrad.py
imports: import numpy
  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 3 for calling the SmoothGrad obj's underlying member method code with example usage: obj.get_averaged_gradients(noisy_images, model, class_index, num_samples) and returns: averaged_grads