class_docstr: Creates multi-class confusion matrix at thresholds from standard inputs.
class_docstr_tok: ["Creates","multi-class","confusion","matrix","at","thresholds","from","standard","inputs","."]
code: def add_input(
      self,
      accumulator: Matrices,
      element: metric_types.StandardMetricInputs,
  ) -> Matrices:
      label, predictions, example_weight = next(
          self._extract_label_prediction_and_weight(
              element,
              eval_config=self._eval_config,
              model_name=self._key.model_name,
              output_name=self._key.output_name,
              example_weighted=self._example_weighted,
              flatten=False,
              require_single_example_weight=True,
          )
      )  # pytype: disable=wrong-arg-types
      if not label.shape:
          raise ValueError(
              "Label missing from example: StandardMetricInputs={}".format(
                  element
              )
          )
      if predictions.shape in ((), (1,)):
          raise ValueError(
              "Predictions shape must be > 1 for multi-class confusion matrix: "
              "shape={}, StandardMetricInputs={}".format(
                  predictions.shape, element
              )
          )
      if label.size > 1:
          actual_class_id = np.argmax(label)
      else:
          actual_class_id = int(label)
      predicted_class_id = np.argmax(predictions)
      example_weight = float(example_weight)
      for threshold in self._thresholds:
          if threshold not in accumulator:
              accumulator[threshold] = {}
          if predictions[predicted_class_id] <= threshold:
              predicted_class_id = NO_PREDICTED_CLASS_ID
          matrix_key = MatrixEntryKey(
              actual_class_id, predicted_class_id
          )
          if matrix_key in accumulator[threshold]:
              accumulator[threshold][matrix_key] += example_weight
          else:
              accumulator[threshold][matrix_key] = example_weight
      return accumulator
  
imports: from typing import Any, Callable, Dict, Iterable, Iterator, List, NamedTuple, Optional, Tuple
  import apache_beam
  import numpy
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
label_desc: Use image node_id 3 for calling the _MultiClassConfusionMatrixCombiner obj's underlying member method code with example usage: obj.add_input(accumulator, element) and returns: accumulator