code: def explain(model, inputs, targets, **kwargs) -> np.ndarray:
      """
      Explain inputs given a model, targets and an explanation method.
      Expecting inputs to be shaped such as (batch_size, nr_channels, ...) or (batch_size, ..., nr_channels).
  
      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 if 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.
      """
  
      if util.find_spec("captum") or util.find_spec("tf_explain"):
          if "method" not in kwargs:
              warnings.warn(
                  f"Using quantus 'explain' function as an explainer without specifying 'method' (string) "
                  f"in kwargs will produce a vanilla 'Gradient' explanation.\n",
                  category=UserWarning,
              )
      elif util.find_spec("zennit"):
          if "attributor" not in kwargs:
              warnings.warn(
                  f"Using quantus 'explain' function as an explainer without specifying 'attributor'"
                  f"in kwargs will produce a vanilla 'Gradient' explanation.\n",
                  category=UserWarning,
              )
  
      elif not __EXTRAS__:
          raise ImportError(
              "Explanation library not found. Please install Captum or Zennit for torch>=1.2 models "
              "and tf-explain for TensorFlow>=2.0."
          )
  
      explanation = get_explanation(model, inputs, targets, **kwargs)
  
      return explanation
  
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 1 for calling a global function with example usage: explain(model, inputs, targets) and returns: explanation