tensorflow_model_analysis/api/model_eval_lib.py [901:936]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class _CombineEvaluationDictionariesFn(beam.CombineFn):
  """CombineFn to combine dictionaries generated by different evaluators."""

  def create_accumulator(self) -> Dict[str, Any]:
    return {}

  def _merge(self, accumulator: Dict[str, Any], output_dict: Dict[str,
                                                                  Any]) -> None:
    intersection = set(accumulator) & set(output_dict)
    if intersection:
      raise ValueError(
          'Dictionaries generated by different evaluators should have '
          'different keys, but keys %s appeared in the output of multiple '
          'evaluators' % intersection)
    accumulator.update(output_dict)

  def add_input(self, accumulator: Dict[str, Any],
                output_dict: Dict[str, Any]) -> Dict[str, Any]:
    if not isinstance(output_dict, dict):
      raise TypeError(
          'for outputs written to by multiple evaluators, the outputs must all '
          'be dictionaries, but got output of type %s, value %s' %
          (type(output_dict), str(output_dict)))
    self._merge(accumulator, output_dict)
    return accumulator

  def merge_accumulators(
      self, accumulators: Iterable[Dict[str, Any]]) -> Dict[str, Any]:
    accumulators = iter(accumulators)
    result = next(accumulators)
    for acc in accumulators:
      self._merge(result, acc)
    return result

  def extract_output(self, accumulator: Dict[str, Any]) -> Dict[str, Any]:
    return accumulator
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



tensorflow_model_analysis/evaluators/evaluator.py [64:99]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class _CombineEvaluationDictionariesFn(beam.CombineFn):
  """CombineFn to combine dictionaries generated by different evaluators."""

  def create_accumulator(self) -> Dict[str, Any]:
    return {}

  def _merge(self, accumulator: Dict[str, Any], output_dict: Dict[str,
                                                                  Any]) -> None:
    intersection = set(accumulator) & set(output_dict)
    if intersection:
      raise ValueError(
          'Dictionaries generated by different evaluators should have '
          'different keys, but keys %s appeared in the output of multiple '
          'evaluators' % intersection)
    accumulator.update(output_dict)

  def add_input(self, accumulator: Dict[str, Any],
                output_dict: Dict[str, Any]) -> Dict[str, Any]:
    if not isinstance(output_dict, dict):
      raise TypeError(
          'for outputs written to by multiple evaluators, the outputs must all '
          'be dictionaries, but got output of type %s, value %s' %
          (type(output_dict), str(output_dict)))
    self._merge(accumulator, output_dict)
    return accumulator

  def merge_accumulators(
      self, accumulators: Iterable[Dict[str, Any]]) -> Dict[str, Any]:
    accumulators = iter(accumulators)
    result = next(accumulators)
    for acc in accumulators:
      self._merge(result, acc)
    return result

  def extract_output(self, accumulator: Dict[str, Any]) -> Dict[str, Any]:
    return accumulator
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



