class_docstr: Interface defining Metrics' API.
docstr: Compute explanations, normalise and take absolute (if was configured so during metric initialization.)
  This method should primarily be used if you need to generate additional explanation
  in metrics body. It encapsulates typical for Quantus pre- and postprocessing approach.
  It will do few things:
      - call model.shape_input (if ModelInterface instance was provided)
      - unwrap model (if ModelInterface instance was provided)
      - call explain_func
      - expand attribution channel
      - (optionally) normalise a_batch
      - (optionally) take np.abs of a_batch
  
  
  Parameters
  -------
  model:
      A model that is subject to explanation.
  x_batch:
      A np.ndarray which contains the input data that are explained.
  y_batch:
      A np.ndarray which contains the output labels that are explained.
  
  Returns
  -------
  a_batch:
      Batch of explanations ready to be evaluated.
docstr_tok: ["Compute","explanations",",","normalise","and","take","absolute","(","if","was","configured","so","during","metric","initialization",".",")","This","method","should","primarily","be","used","if","you","need","to","generate","additional","explanation","in","metrics","body",".","It","encapsulates","typical","for","Quantus","pre-","and","postprocessing","approach",".","It","will","do","few","things",":","-","call","model.shape_input","(","if","ModelInterface","instance","was","provided",")","-","unwrap","model","(","if","ModelInterface","instance","was","provided",")","-","call","explain_func","-","expand","attribution","channel","-","(","optionally",")","normalise","a_batch","-","(","optionally",")","take","np.abs","of","a_batch","Parameters","--","--","--","-","model",":","A","model","that","is","subject","to","explanation",".","x_batch",":","A","np.ndarray","which","contains","the","input","data","that","are","explained",".","y_batch",":","A","np.ndarray","which","contains","the","output","labels","that","are","explained",".","Returns","--","--","--","-","a_batch",":","Batch","of","explanations","ready","to","be","evaluated","."]
code: def explain_batch(
      self,
      model: Union[ModelInterface, keras.Model, nn.Module],
      x_batch: np.ndarray,
      y_batch: np.ndarray,
  ) -> np.ndarray:
      """
      Compute explanations, normalise and take absolute (if was configured so during metric initialization.)
      This method should primarily be used if you need to generate additional explanation
      in metrics body. It encapsulates typical for Quantus pre- and postprocessing approach.
      It will do few things:
          - call model.shape_input (if ModelInterface instance was provided)
          - unwrap model (if ModelInterface instance was provided)
          - call explain_func
          - expand attribution channel
          - (optionally) normalise a_batch
          - (optionally) take np.abs of a_batch
  
  
      Parameters
      -------
      model:
          A model that is subject to explanation.
      x_batch:
          A np.ndarray which contains the input data that are explained.
      y_batch:
          A np.ndarray which contains the output labels that are explained.
  
      Returns
      -------
      a_batch:
          Batch of explanations ready to be evaluated.
      """
  
      if isinstance(model, ModelInterface):
          # Sometimes the model is our wrapper, but sometimes raw Keras/Torch model.
          x_batch = model.shape_input(
              x=x_batch,
              shape=x_batch.shape,
              channel_first=True,
              batched=True,
          )
          model = model.get_model()
  
      a_batch = self.explain_func(
          model=model,
          inputs=x_batch,
          targets=y_batch,
          **self.explain_func_kwargs,
      )
      a_batch = utils.expand_attribution_channel(a_batch, x_batch)
      asserts.assert_attributions(x_batch=x_batch, a_batch=a_batch)
  
      # Normalise and take absolute values of the attributions, if configured during metric instantiation.
      if self.normalise:
          a_batch = self.normalise_func(a_batch)
  
      if self.abs:
          a_batch = np.abs(a_batch)
  
      return a_batch
  
imports: from __future__ import annotations
  import functools
  import logging
  import os
  import sys
  from abc import abstractmethod
  from typing import Any, Callable, ClassVar, Dict, Generator, Generic, Sequence, Set, TypeVar, Optional, Union, TYPE_CHECKING, no_type_check
  import matplotlib.pyplot
  import numpy
  from sklearn.utils import gen_batches
  from tqdm.auto import tqdm
  from quantus.helpers import asserts, utils, warn
  from quantus.functions.normalise_func import normalise_by_max
  from quantus.helpers.enums import DataType, EvaluationCategory, ModelType, ScoreDirection
  from quantus.helpers.model.model_interface import ModelInterface
label_desc: Use image node_id 13 for calling the Metric obj's underlying member method code with example usage: obj.explain_batch(model, x_batch, y_batch) and returns: a_batch