code: def __init__(self, model, data, batch_size=50, local_smoothing=0):
      # try and import pytorch
      global torch
      if torch is None:
          import torch
  
          if version.parse(torch.__version__) < version.parse("0.4"):
              warnings.warn(
                  "Your PyTorch version is older than 0.4 and not supported."
              )
  
      # check if we have multiple inputs
      self.multi_input = False
      if isinstance(data, list):
          self.multi_input = True
      if not isinstance(data, list):
          data = [data]
  
      # for consistency, the method signature calls for data as the model input.
      # However, within this class, self.model_inputs is the input (i.e. the data passed by the user)
      # and self.data is the background data for the layer we want to assign importances to. If this layer is
      # the input, then self.data = self.model_inputs
      self.model_inputs = data
      self.batch_size = batch_size
      self.local_smoothing = local_smoothing
  
      self.layer = None
      self.input_handle = None
      self.interim = False
      if type(model) == tuple:
          self.interim = True
          model, layer = model
          model = model.eval()
          self.add_handles(layer)
          self.layer = layer
  
          # now, if we are taking an interim layer, the 'data' is going to be the input
          # of the interim layer; we will capture this using a forward hook
          with torch.no_grad():
              _ = model(*data)
              interim_inputs = self.layer.target_input
              if type(interim_inputs) is tuple:
                  # this should always be true, but just to be safe
                  self.data = [
                      i.clone().detach() for i in interim_inputs
                  ]
              else:
                  self.data = [interim_inputs.clone().detach()]
      else:
          self.data = data
      self.model = model.eval()
  
      multi_output = False
      outputs = self.model(*self.model_inputs)
      if len(outputs.shape) > 1 and outputs.shape[1] > 1:
          multi_output = True
      self.multi_output = multi_output
  
      if not self.multi_output:
          self.gradients = [None]
      else:
          self.gradients = [None for i in range(outputs.shape[1])]
  
imports: import warnings
  import numpy
  import pandas
  from packaging import version
  from .._explanation import Explanation
  from ..explainers._explainer import Explainer
  from ..explainers.tf_utils import _get_graph, _get_model_inputs, _get_model_output, _get_session
label_desc: Use image node_id 1 to create a new _PyTorchGradient object from inherited base classes: Explainer with example: obj = _PyTorchGradient(model, data, batch_size, local_smoothing)