class_docstr: Perform Grad CAM algorithm for a given input
  
  Paper: [Grad-CAM: Visual Explanations from Deep Networks
          via Gradient-based Localization](https://arxiv.org/abs/1610.02391)
class_docstr_tok: ["Perform","Grad","CAM","algorithm","for","a","given","input","Paper",":","[","Grad-CAM",":","Visual","Explanations","from","Deep","Networks","via","Gradient-based","Localization","]","(","https",":","\/\/arxiv.org\/abs\/1610.02391",")"]
docstr: Search for the last convolutional layer to perform Grad CAM, as stated
  in the original paper.
  
  Args:
      model (tf.keras.Model): tf.keras model to inspect
  
  Returns:
      str: Name of the target layer
docstr_tok: ["Search","for","the","last","convolutional","layer","to","perform","Grad","CAM",",","as","stated","in","the","original","paper",".","Args",":","model","(","tf.keras.Model",")",":","tf.keras","model","to","inspect","Returns",":","str",":","Name","of","the","target","layer"]
code: def infer_grad_cam_target_layer(model):
      """
      Search for the last convolutional layer to perform Grad CAM, as stated
      in the original paper.
  
      Args:
          model (tf.keras.Model): tf.keras model to inspect
  
      Returns:
          str: Name of the target layer
      """
      for layer in reversed(model.layers):
          # Select closest 4D layer to the end of the network.
          if len(layer.output_shape) == 4:
              return layer.name
  
      raise ValueError(
          "Model does not seem to contain 4D layer. Grad CAM cannot be applied."
      )
  
file_path: tf-explain/tf_explain/core/grad_cam.py
imports: import numpy
  import tensorflow
  import cv2
  from tf_explain.utils.display import grid_display, heatmap_display
  from tf_explain.utils.saver import save_rgb
label_desc: Use image node_id 2 for calling the GradCAM obj's underlying member method code with example usage: obj.infer_grad_cam_target_layer(model) and returns: layer