class_docstr: Interface defining Metrics' API.
docstr: Creates iterator to iterate over all batched instances in data dictionary.
  Each iterator output element is a keyword argument dictionary with
  string keys.
  
  Each item key in the input data dictionary has to be of type string.
  - If the item value is not a sequence, the respective item key/value pair
    will be written to each iterator output dictionary.
  - If the item value is a sequence and the item key ends with '_batch',
    a check will be made to make sure length matches number of instances.
    The values of the batch instances in the sequence will be added to the respective
    iterator output dictionary with the '_batch' suffix removed.
  - If the item value is a sequence but doesn't end with '_batch', it will be treated
    as a simple value and the respective item key/value pair will be
    written to each iterator output dictionary.
  
  Parameters
  ----------
  data: dict[str, any]
      The data input dictionary.
  batch_size: int
      The batch size to be used.
  
  Returns
  -------
  iterator:
      Each iterator output element is a keyword argument dictionary (string keys).
docstr_tok: ["Creates","iterator","to","iterate","over","all","batched","instances","in","data","dictionary",".","Each","iterator","output","element","is","a","keyword","argument","dictionary","with","string","keys",".","Each","item","key","in","the","input","data","dictionary","has","to","be","of","type","string",".","-","If","the","item","value","is","not","a","sequence",",","the","respective","item","key\/value","pair","will","be","written","to","each","iterator","output","dictionary",".","-","If","the","item","value","is","a","sequence","and","the","item","key","ends","with","'_batch","'",",","a","check","will","be","made","to","make","sure","length","matches","number","of","instances",".","The","values","of","the","batch","instances","in","the","sequence","will","be","added","to","the","respective","iterator","output","dictionary","with","the","'_batch","'","suffix","removed",".","-","If","the","item","value","is","a","sequence","but","does","n't","end","with","'_batch","'",",","it","will","be","treated","as","a","simple","value","and","the","respective","item","key\/value","pair","will","be","written","to","each","iterator","output","dictionary",".","Parameters","--","--","--","--","--","data",":","dict","[","str",",","any","]","The","data","input","dictionary",".","batch_size",":","int","The","batch","size","to","be","used",".","Returns","--","--","--","-","iterator",":","Each","iterator","output","element","is","a","keyword","argument","dictionary","(","string","keys",")","."]
code: def generate_batches(
      self,
      data: D,
      batch_size: int,
  ) -> Generator[D, None, None]:
      """
      Creates iterator to iterate over all batched instances in data dictionary.
      Each iterator output element is a keyword argument dictionary with
      string keys.
  
      Each item key in the input data dictionary has to be of type string.
      - If the item value is not a sequence, the respective item key/value pair
        will be written to each iterator output dictionary.
      - If the item value is a sequence and the item key ends with '_batch',
        a check will be made to make sure length matches number of instances.
        The values of the batch instances in the sequence will be added to the respective
        iterator output dictionary with the '_batch' suffix removed.
      - If the item value is a sequence but doesn't end with '_batch', it will be treated
        as a simple value and the respective item key/value pair will be
        written to each iterator output dictionary.
  
      Parameters
      ----------
      data: dict[str, any]
          The data input dictionary.
      batch_size: int
          The batch size to be used.
  
      Returns
      -------
      iterator:
          Each iterator output element is a keyword argument dictionary (string keys).
  
      """
      n_instances = len(data["x_batch"])
  
      single_value_kwargs: Dict[str, Any] = {}
      batched_value_kwargs: Dict[str, Any] = {}
  
      for key, value in list(data.items()):
          # If data-value is not a Sequence or a string, create list of value with length of n_instances.
          if not isinstance(
              value, (Sequence, np.ndarray)
          ) or isinstance(value, str):
              single_value_kwargs[key] = value
  
          # If data-value is a sequence and ends with '_batch', only check for correct length.
          elif key.endswith("_batch"):
              if len(value) != n_instances:
                  # Sequence has to have correct length.
                  raise ValueError(
                      f"'{key}' has incorrect length (expected: {n_instances}, is: {len(value)})"
                  )
              else:
                  batched_value_kwargs[key] = value
  
          # If data-value is a sequence and doesn't end with '_batch', create
          # list of repeated sequences with length of n_instances.
          else:
              single_value_kwargs[key] = [
                  value for _ in range(n_instances)
              ]
  
      n_batches = np.ceil(n_instances / batch_size)
  
      with tqdm(
          total=n_batches, disable=not self.display_progressbar
      ) as pbar:
          for batch_idx in gen_batches(n_instances, batch_size):
              batch = {
                  key: value[batch_idx.start : batch_idx.stop]
                  for key, value in batched_value_kwargs.items()
              }
              # Yield batch dictionary including single value keyword arguments.
              yield {**batch, **single_value_kwargs}
              # Update progressbar by number of samples in this batch.
              pbar.update(batch_idx.stop - batch_idx.start)
  
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 7 for calling the Metric obj's underlying member method code with example usage: obj.generate_batches(data, batch_size) without return types