code: def get_explanation(model, inputs, targets, **kwargs):
      """
      Generate explanation array based on the type of input model and user specifications.
      For tensorflow models, tf.explain is used.
      For pytorch models, either captum or zennit is used, depending on which module is installed.
      If both are installed, captum is used per default. Setting the xai_lib kwarg to "zennit" uses zennit instead.
  
      Parameters
      ----------
      model: torch.nn.Module, tf.keras.Model
              A model that is used for explanation.
      inputs: np.ndarray
           The inputs that ought to be explained.
      targets: np.ndarray
           The target lables that should be used in the explanation.
      kwargs: optional
              Keyword arguments. Pass as "explain_func_kwargs" dictionary when working with a metric class.
              Pass as regular kwargs when using the stnad-alone function.
  
              xai_lib: string, optional
                  XAI library: captum, tf-explain or zennit.
              method: string, optional
                  XAI method (used with captum and tf-explain libraries).
              attributor: string, optional
                  XAI method (used with zennit).
              xai_lib_kwargs: dictionary, optional
                  Keyword arguments to be passed to the attribution function.
              softmax: boolean, optional
                  Indicated whether softmax activation in the last layer shall be removed.
              channel_first: boolean, optional
                  Indicates of the image dimensions are channel first, or channel last.
                  Inferred from the input shape if None.
              reduce_axes: tuple
                  Indicates the indices of dimensions of the output explanation array to be summed. For example, an input
                  array of shape (8, 28, 28, 3) with keepdims=True and reduce_axes = (-1,) will return an array of shape
                  (8, 28, 28, -1). Passing "()" will keep the original dimensions.
              keepdims: boolean
                  Indicated if the reduced axes shall be preserved (True) or removed (False).
      Returns
      -------
      explanation: np.ndarray
           Returns np.ndarray of same shape as inputs.
      """
      xai_lib = kwargs.get("xai_lib", "captum")
      if isinstance(model, torch.nn.Module):
          if util.find_spec("captum") and util.find_spec("zennit"):
              if xai_lib == "captum":
                  return generate_captum_explanation(
                      model, inputs, targets, **kwargs
                  )
              if xai_lib == "zennit":
                  return generate_zennit_explanation(
                      model, inputs, targets, **kwargs
                  )
          if util.find_spec("captum"):
              return generate_captum_explanation(
                  model, inputs, targets, **kwargs
              )
          if util.find_spec("zennit"):
              return generate_zennit_explanation(
                  model, inputs, targets, **kwargs
              )
      if isinstance(model, tf.keras.Model):
          if util.find_spec("tf_explain"):
              return generate_tf_explanation(
                  model, inputs, targets, **kwargs
              )
          else:
              raise ValueError(
                  f"Model is of type tf.keras.Model but tf_explain is not installed."
              )
  
      raise ValueError(
          f"Model needs to be tf.keras.Model or torch.nn.Module but is {type(model)}. "
          "Please install Captum or Zennit for torch>=1.2 models and tf-explain for TensorFlow>=2.0."
      )
  
file_path: Quantus/quantus/functions/explanation_func.py
imports: import warnings
  from importlib import util
  from typing import Optional, Union
  import numpy
  import quantus
  import scipy
  from quantus.helpers import constants
  from quantus.helpers import __EXTRAS__
  from quantus.helpers.model.model_interface import ModelInterface
  from quantus.helpers.utils import get_baseline_value, infer_channel_first, make_channel_last, get_wrapped_model
label_desc: Use image node_id 2 for calling a global function with example usage: get_explanation(model, inputs, targets) and returns: generate_captum_explanation, generate_zennit_explanation, generate_tf_explanation, generate_captum_explanation, generate_zennit_explanation