code: def encode_key(key: types.FPLKeyType) -> bytes:
      """Encode a dictionary key as a string.
  
      For encoding dictionary keys in the prediction, label and feature
      dictionaries. We assume that they are either Tuples of bytes, or bytes.
  
      Implementation details:
        Strings are encoded as $Bytes$<String>
        Tuples of strings are encoded as:
          $Tuple$<len(tuple)>$len(tuple[0])$...$len(tuple[n])$tuple[0]$...$tuple[n]
          e.g. ('apple', 'banana', 'cherry') gets encoded as
          $Tuple$3$5$6$6$apple$banana$cherry
  
      Args:
        key: Dictionary key to encode.
  
      Returns:
        Encoded dictionary key.
  
      Raises:
        TypeError: Dictionary key is not either a Tuple of bytes/unicode,
          or bytes/unicode.
      """
  
      if isinstance(key, tuple):
          if not all(
              isinstance(elem, bytes) or isinstance(elem, str)
              for elem in key
          ):
              raise TypeError(
                  "if key is tuple, all elements should be strings. "
                  "key was: %s" % key
              )
          utf8_keys = [tf.compat.as_bytes(elem) for elem in key]
          length_strs = [
              tf.compat.as_bytes("%d" % len(key)) for key in utf8_keys
          ]
          return (
              _TUPLE_KEY_PREFIX
              + tf.compat.as_bytes("%d" % len(length_strs))
              + b"$"
              + b"$".join(length_strs)
              + b"$"
              + b"$".join(utf8_keys)
          )
      elif isinstance(key, bytes) or isinstance(key, str):
          return b"$Bytes$" + tf.compat.as_bytes(key)
      else:
          raise TypeError(
              "key has unrecognised type: type: %s, value %s"
              % (type(key), key)
          )
  
file_path: model-analysis/tensorflow_model_analysis/eval_saved_model/encoding.py
imports: import tensorflow
  from tensorflow_model_analysis.api import types
  from google.protobuf import any_pb2
  from tensorflow.core.protobuf import meta_graph_pb2
label_desc: Use image node_id 2 for calling a global function with example usage: encode_key(key) and returns: unknown, unknown