code: def extract_signature_inputs_or_outputs_with_prefix(
      prefix: str,
      # Inputs and outputs are not actually Dicts, but behave like them
      signature_inputs_or_outputs: Dict[str, meta_graph_pb2.TensorInfo],
      key_if_single_element: Optional[str] = None,
  ) -> Dict[str, meta_graph_pb2.TensorInfo]:
      """Extracts signature outputs with the given prefix.
  
      This is the reverse of _wrap_and_check_metrics / _wrap_and_check_outputs and
      _prefix_output_keys in tf.estimator.export.ExportOutput.
  
      This is designed to extract structures from the  SignatureDef outputs map.
  
      Structures of the following form:
          <prefix>/key1
          <prefix>/key2
      will map to dictionary elements like so:
          {key1: value1, key2: value2}
  
      Structures of the following form:
          <prefix>
          <prefix>_extrastuff
          <prefix>morestuff
      will map to dictionary elements like so:
          {<prefix>: value1, <prefix>_extrastuff: value2, <prefix>morestuff: value3}
  
      Args:
        prefix: Prefix to extract
        signature_inputs_or_outputs: Signature inputs or outputs to extract from
        key_if_single_element: Key to use in the dictionary if the SignatureDef map
          had only one entry with key <prefix> representing a single tensor.
  
      Returns:
        Dictionary extracted as described above. The values will be the TensorInfo
        associated with the keys.
  
      Raises:
        ValueError: There were duplicate keys.
      """
      matched_prefix = False
      result = {}
      for k, v in signature_inputs_or_outputs.items():
          if k.startswith(prefix + "/"):
              key = k[len(prefix) + 1 :]
          elif k.startswith(prefix):
              if k == prefix:
                  matched_prefix = True
              key = k
          else:
              continue
  
          if key in result:
              raise ValueError(
                  'key "%s" already in dictionary. you might have repeated keys. '
                  'prefix was "%s", signature_def values were: %s'
                  % (prefix, key, signature_inputs_or_outputs)
              )
          result[key] = v
  
      if key_if_single_element and matched_prefix and len(result) == 1:
          return {key_if_single_element: result[prefix]}
  
      return result
  
imports: import collections
  from typing import Dict, List, Optional, Tuple, Union
  import tensorflow
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.eval_saved_model import constants
  from tensorflow_model_analysis.eval_saved_model import encoding
  from tensorflow_model_analysis.eval_saved_model import util
  from google.protobuf import any_pb2
  from tensorflow.core.protobuf import meta_graph_pb2
label_desc: Use image node_id 1 for calling a global function with example usage: extract_signature_inputs_or_outputs_with_prefix(prefix, signature_inputs_or_outputs, key_if_single_element) and returns: result, dict