code: def _register_forward_backward_hook(self):
      def forward_hook_input(m, i, o):
          self.intermediate_act.append(i[0].data.clone())
  
      def forward_hook_output(m, i, o):
          self.intermediate_act.append(o.data.clone())
  
      def backward_hook(m, grad_i, grad_o):
          self.intermediate_grad.append(grad_o[0].data.clone())
  
      if self.target_layer is not None:
          if self.use_inp:
              self.handle_forward_hook = (
                  self.target_layer.register_forward_hook(
                      forward_hook_input
                  )
              )
          else:
              self.handle_forward_hook = (
                  self.target_layer.register_forward_hook(
                      forward_hook_output
                  )
              )
  
          self.handle_backward_hook = (
              self.target_layer.register_backward_hook(backward_hook)
          )
  
file_path: tensorwatch/tensorwatch/saliency/gradcam.py
imports: import torch
  from .backprop import VanillaGradExplainer
label_desc: Use image node_id 2 for calling the GradCAMExplainer obj's underlying member method code with example usage: obj._register_forward_backward_hook() without return types