class_docstr: Test class with extra methods for unit-testing TFMA models / metrics.
class_docstr_tok: ["Test","class","with","extra","methods","for","unit-testing","TFMA","models","\/","metrics","."]
docstr: Checks metrics computed using Beam.
  
  Metrics will be computed over all examples, without any slicing. If you
  want to provide your own PCollection (e.g. read a large number of examples
  from a file), if you want to check metrics over certain slices, or if you
  want to add additional post-export metrics, use the more general
  assertGeneralMetricsComputedWithBeamAre.
  
  Example usage:
    self.assertMetricsComputedWithBeamAre(
      eval_saved_model_path=path,
      serialized_examples=[self.makeExample(age=5, label=1.0),
                           self.makeExample(age=10, label=0.0)],
      expected_metrics={'average_loss': 0.1})
  
  Args:
    eval_saved_model_path: Path to the directory containing the
      EvalSavedModel.
    serialized_examples: List of serialized example bytes.
    expected_metrics: Dictionary of expected metric values.
    add_metrics_callbacks: Optional. Callbacks for adding additional metrics.
docstr_tok: ["Checks","metrics","computed","using","Beam",".","Metrics","will","be","computed","over","all","examples",",","without","any","slicing",".","If","you","want","to","provide","your","own","PCollection","(","e.g",".","read","a","large","number","of","examples","from","a","file",")",",","if","you","want","to","check","metrics","over","certain","slices",",","or","if","you","want","to","add","additional","post-export","metrics",",","use","the","more","general","assertGeneralMetricsComputedWithBeamAre",".","Example","usage",":","self.assertMetricsComputedWithBeamAre","(","eval_saved_model_path=path",",","serialized_examples=","[","self.makeExample","(","age=5",",","label=1.0",")",",","self.makeExample","(","age=10",",","label=0.0",")","]",",","expected_metrics=","{","'average_loss","'",":","0.1","}",")","Args",":","eval_saved_model_path",":","Path","to","the","directory","containing","the","EvalSavedModel",".","serialized_examples",":","List","of","serialized","example","bytes",".","expected_metrics",":","Dictionary","of","expected","metric","values",".","add_metrics_callbacks",":","Optional",".","Callbacks","for","adding","additional","metrics","."]
code: def assertMetricsComputedWithBeamAre(
      self,
      eval_saved_model_path: str,
      serialized_examples: List[bytes],
      expected_metrics: Dict[str, Any],
      add_metrics_callbacks: Optional[
          List[types.AddMetricsCallbackType]
      ] = None,
  ):
      """Checks metrics computed using Beam.
  
      Metrics will be computed over all examples, without any slicing. If you
      want to provide your own PCollection (e.g. read a large number of examples
      from a file), if you want to check metrics over certain slices, or if you
      want to add additional post-export metrics, use the more general
      assertGeneralMetricsComputedWithBeamAre.
  
      Example usage:
        self.assertMetricsComputedWithBeamAre(
          eval_saved_model_path=path,
          serialized_examples=[self.makeExample(age=5, label=1.0),
                               self.makeExample(age=10, label=0.0)],
          expected_metrics={'average_loss': 0.1})
  
      Args:
        eval_saved_model_path: Path to the directory containing the
          EvalSavedModel.
        serialized_examples: List of serialized example bytes.
        expected_metrics: Dictionary of expected metric values.
        add_metrics_callbacks: Optional. Callbacks for adding additional metrics.
      """
  
      def check_metrics(got):
          """Check metrics callback."""
          try:
              self.assertEqual(
                  1,
                  len(got),
                  "expecting metrics for exactly one slice, but got %d "
                  "slices instead. metrics were: %s" % (len(got), got),
              )
              (slice_key, value) = got[0]
              self.assertEqual((), slice_key)
              self.assertDictElementsWithinBounds(
                  got_values_dict=value,
                  expected_values_dict=expected_metrics,
              )
          except AssertionError as err:
              raise beam_util.BeamAssertException(err)
  
      eval_config = config_pb2.EvalConfig()
      eval_shared_model = model_eval_lib.default_eval_shared_model(
          eval_saved_model_path=eval_saved_model_path,
          add_metrics_callbacks=add_metrics_callbacks,
      )
      extractors = model_eval_lib.default_extractors(
          eval_config=eval_config, eval_shared_model=eval_shared_model
      )
  
      tfx_io = raw_tf_record.RawBeamRecordTFXIO(
          physical_format="inmemory",
          raw_record_column_name=constants.ARROW_INPUT_COLUMN,
          telemetry_descriptors=["TFMATest"],
      )
      with beam.Pipeline() as pipeline:
          # pylint: disable=no-value-for-parameter
          (metrics, _), _ = (
              pipeline
              | "CreateExamples" >> beam.Create(serialized_examples)
              | "BatchExamples" >> tfx_io.BeamSource()
              | "InputsToExtracts"
              >> model_eval_lib.BatchedInputsToExtracts()
              | "Extract" >> Extract(extractors=extractors)
              | "ComputeMetricsAndPlots"
              >> legacy_metrics_and_plots_evaluator._ComputeMetricsAndPlots(  # pylint: disable=protected-access
                  eval_shared_model=eval_shared_model
              )
          )
          # pylint: enable=no-value-for-parameter
  
          beam_util.assert_that(metrics, check_metrics)
  
imports: from typing import Any, Dict, List, Optional
  import apache_beam
  from apache_beam.testing import util
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import model_eval_lib
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.eval_saved_model import load
  from tensorflow_model_analysis.eval_saved_model import testutil
  from tensorflow_model_analysis.evaluators import legacy_metrics_and_plots_evaluator
  from tensorflow_model_analysis.extractors import extractor
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.slicer import slicer_lib
  from tfx_bsl.tfxio import raw_tf_record
label_desc: Use image node_id 7 for calling the TestCase obj's underlying member method code with example usage: obj.assertMetricsComputedWithBeamAre(eval_saved_model_path, serialized_examples, expected_metrics, add_metrics_callbacks) without return types