class_docstr: Base combiner for aggregating metrics for keras based models.
class_docstr_tok: ["Base","combiner","for","aggregating","metrics","for","keras","based","models","."]
code: def __init__(
      self,
      keys: List[metric_types.MetricKey],
      model_name: str,
      model_loader: types.ModelLoader,
      eval_config: Optional[config_pb2.EvalConfig],
      desired_batch_size: Optional[int] = None,
      beam_metrics_prefix: str = "",
  ):
      super().__init__({model_name: model_loader})
      self._keys = keys
      self._model_name = model_name
      self._eval_config = eval_config
      self._desired_batch_size = desired_batch_size
      self._model = None
      # This combiner makes use of the TFMetricsAccumulator to track the inputs
      # and outputs. While the TFMetricsAccumulator is designed to store output
      # weights for each input, this doesn't work well with metrics from the keras
      # model because all the outputs get mixed together. So in this case the
      # _output_names will contain ['', output1, output2, ...] and _output_counts
      # will contain the corresponding counts of metrics for each output (with ''
      # including the counts of metrics that are aggregations over multiple
      # outputs - e.g. weighted loss). For the actual computations, we will store
      # the inputs under the respective output indices (with '' having no inputs),
      # but store all the metric weights under output index 0.
      self._output_names = sorted(
          set(key.output_name or "" for key in keys)
      )
      counts = collections.defaultdict(int)
      for key in keys:
          if key.output_name:
              counts[key.output_name] += 1
      counts[""] = len(keys)
      self._output_counts = [
          counts[name] for name in self._output_names
      ]
      self._batch_size_beam_metric_dist = (
          beam.metrics.Metrics.distribution(
              constants.METRICS_NAMESPACE,
              "{}_combine_batch_size".format(beam_metrics_prefix),
          )
      )
      self._total_input_byte_size_beam_metric_dist = (
          beam.metrics.Metrics.distribution(
              constants.METRICS_NAMESPACE,
              "{}_combine_batch_bytes_size".format(beam_metrics_prefix),
          )
      )
      self._num_compacts = beam.metrics.Metrics.counter(
          constants.METRICS_NAMESPACE, "num_compacts"
      )
  
imports: import collections
  from itertools import chain
  from typing import Dict, Iterable, List, Optional
  import apache_beam
  import numpy
  import tensorflow
  from tensorflow_model_analysis import constants
  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.metrics import tf_metric_accumulators
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.utils import model_util
  from tensorflow_model_analysis.utils import util
label_desc: Use image node_id 1 to create a new _KerasCombiner object from inherited base classes: model_util with example: obj = _KerasCombiner(keys, model_name, model_loader, eval_config, desired_batch_size, beam_metrics_prefix)