class_docstr: Combines semantic segmentation confusion matrices.
class_docstr_tok: ["Combines","semantic","segmentation","confusion","matrices","."]
code: def add_input(
      self,
      accumulator: Dict[int, Matrix],
      element: metric_types.StandardMetricInputs,
  ) -> Dict[int, Matrix]:
      ground_truth = element.get_labels()
      prediction = element.get_predictions()
  
      if ground_truth.ndim != 2:
          raise ValueError(
              "The ground truth should be in 2d. "
              f"But the shape is {ground_truth.shape}"
          )
      if ground_truth.shape != prediction.shape:
          raise ValueError(
              f"The shape of prediction {prediction.shape} does not"
              f" match the shape of ground truth {ground_truth.shape}"
          )
  
      for class_id in self._class_ids:
          class_true_positive = np.sum(
              np.logical_and(
                  ground_truth == class_id, prediction == class_id
              )
          )
          class_false_positive = np.sum(
              np.logical_and(
                  np.logical_and(
                      ground_truth != class_id, prediction == class_id
                  ),
                  ground_truth != self._ignore_ground_truth_id,
              )
          )
          class_false_negative = np.sum(
              np.logical_and(
                  ground_truth == class_id, prediction != class_id
              )
          )
          class_true_negative = np.sum(
              np.logical_and(
                  np.logical_and(
                      ground_truth != class_id, prediction != class_id
                  ),
                  ground_truth != self._ignore_ground_truth_id,
              )
          )
  
          class_confusion_matrix = Matrix(
              tp=class_true_positive,
              tn=class_true_negative,
              fp=class_false_positive,
              fn=class_false_negative,
          )
          if class_id not in accumulator:
              accumulator[class_id] = class_confusion_matrix
          else:
              accumulator[class_id] = Matrix(
                  tp=accumulator[class_id].tp
                  + class_confusion_matrix.tp,
                  tn=accumulator[class_id].tn
                  + class_confusion_matrix.tn,
                  fp=accumulator[class_id].fp
                  + class_confusion_matrix.fp,
                  fn=accumulator[class_id].fn
                  + class_confusion_matrix.fn,
              )
      return accumulator
  
imports: import abc
  from typing import Any, Dict, Iterable, List, Optional, Union
  import apache_beam
  import numpy
  from tensorflow_model_analysis.contrib.aggregates import binary_confusion_matrices
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.metrics import metric_util
  from tensorflow_model_analysis.metrics import preprocessors
  from tensorflow_model_analysis.proto import config_pb2
label_desc: Use image node_id 3 for calling the _SemanticSegmentationConfusionMatrixCombiner obj's underlying member method code with example usage: obj.add_input(accumulator, element) and returns: accumulator