code: def get_example_decoder(
      example_spec, batched=False, compress_image=False
  ):
      """Get an example decoder function for a nested spec.
  
      Given a spec, returns an example decoder function. The decoder function parses
      string serialized example protos into tensors according to the given spec.
  
      Args:
        example_spec: list/tuple/nest of ArraySpecs describing a single example.
        batched: Boolean indicating if the decoder will receive batches of
          serialized data.
        compress_image: Whether to decompress image. It is assumed that any uint8
          tensor of rank 3 with shape (w,h,c) is an image. If the tensor was
          compressed in the encoder, it needs to be decompressed.
  
      Returns:
        Function
  
        ```python
        decoder(serialized_proto: tf.tensor[string]) -> example_spec nest of tensors
        ```
      """
      features_dict = {}
      parsers = []
  
      for path, spec in nest_utils.flatten_with_joined_paths(
          example_spec
      ):
          feature, parser = _get_feature_parser(
              spec.shape, spec.dtype, compress_image
          )
          features_dict[path] = feature
          parsers.append((path, parser))
  
      def _example_decoder(serialized):
          """Parses string serialized example protos into tensors."""
          if batched:
              raw_features = tf.io.parse_example(
                  serialized=serialized, features=features_dict
              )
  
              decoded_features = []
  
              dtypes = [s.dtype for s in tf.nest.flatten(example_spec)]
              if len(parsers) != len(dtypes):
                  raise ValueError(
                      "Decoding failed: Number of parsers (%d) does not match the number "
                      "of items in the example_spec (%d)"
                      % (len(parsers), len(dtypes))
                  )
  
              for (path, parser), dtype in zip(parsers, dtypes):
                  decoded_features.append(
                      tf.map_fn(parser, raw_features[path], dtype=dtype)
                  )
  
              return tf.nest.pack_sequence_as(
                  example_spec, decoded_features
              )
          else:
              raw_features = tf.io.parse_single_example(
                  serialized=serialized, features=features_dict
              )
              return tf.nest.pack_sequence_as(
                  example_spec,
                  [
                      parser(raw_features[path])
                      for path, parser in parsers
                  ],
              )
  
      return _example_decoder
  
file_path: agents/tf_agents/utils/example_encoding.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from collections import abc
  import io
  import gin
  import numpy
  from PIL import Image
  import tensorflow
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 3 for calling a global function with example usage: get_example_decoder(example_spec, batched, compress_image) and returns: _example_decoder, tf, tf