code: def load_and_deserialize_metrics(
      output_path: str,
      output_file_format: str = _TFRECORD_FORMAT,
      slice_specs: Optional[Iterable[slicer.SingleSliceSpec]] = None,
  ) -> Iterator[metrics_for_slice_pb2.MetricsForSlice]:
      """Read and deserialize the MetricsForSlice records.
  
      Args:
        output_path: Path or pattern to search for metrics files under. If a
          directory is passed, files matching 'metrics*' will be searched for.
        output_file_format: Optional file extension to filter files by and the
          format to use for parsing. The default value is tfrecord.
        slice_specs: A set of SingleSliceSpecs to use for filtering returned
          metrics. The metrics for a given slice key will be returned if that slice
          key matches any of the slice_specs.
  
      Yields:
        MetricsForSlice protos found in matching files.
      """
      if tf.io.gfile.isdir(output_path):
          output_path = os.path.join(output_path, constants.METRICS_KEY)
      pattern = _match_all_files(output_path)
      if output_file_format:
          pattern = pattern + "." + output_file_format
      paths = tf.io.gfile.glob(pattern)
      if not paths:
          # For backwards compatibility, check for files without an explicit suffix,
          # but still use the output_file_format for parsing.
          no_suffix_pattern = _match_all_files(output_path)
          paths = tf.io.gfile.glob(no_suffix_pattern)
      for value in _raw_value_iterator(paths, output_file_format):
          metrics = metrics_for_slice_pb2.MetricsForSlice.FromString(
              value
          )
          if slice_specs and not slicer.slice_key_matches_slice_specs(
              slicer.deserialize_slice_key(metrics.slice_key),
              slice_specs,
          ):
              continue
          yield metrics
  
imports: import itertools
  import os
  from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union
  from absl import logging
  import apache_beam
  import numpy
  import pyarrow
  import tensorflow
  from tensorflow_model_analysis import constants
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.evaluators import evaluator
  from tensorflow_model_analysis.evaluators import metrics_validator
  from tensorflow_model_analysis.metrics import calibration_plot
  from tensorflow_model_analysis.metrics import confusion_matrix_plot
  from tensorflow_model_analysis.metrics import metric_specs
  from tensorflow_model_analysis.metrics import metric_types
  from tensorflow_model_analysis.post_export_metrics import metric_keys
  from tensorflow_model_analysis.proto import config_pb2
  from tensorflow_model_analysis.proto import metrics_for_slice_pb2
  from tensorflow_model_analysis.proto import validation_result_pb2
  from tensorflow_model_analysis.slicer import slicer_lib
  from tensorflow_model_analysis.utils import math_util
  from tensorflow_model_analysis.writers import writer
  from google.protobuf import wrappers_pb2
label_desc: Use image node_id 4 for calling a global function with example usage: load_and_deserialize_metrics(output_path, output_file_format, slice_specs) without return types