code: def _get_feature_encoder(
      shape, dtype, compress_image=False, image_quality=95
  ):
      """Get feature encoder function for shape and dtype.
  
      Args:
        shape: An array shape
        dtype: A list of dtypes.
        compress_image: Whether to compress image. It is assumed that any uint8
          tensor of rank 3 with shape (w,h,c) is an image.
        image_quality: An optional int. Defaults to 95. Quality of the compression
          from 0 to 100 (higher is better and slower).
  
      Returns:
        A tf.train.Feature encoder.
      """
      shape = _validate_shape(shape)
      dtype = _validate_dtype(dtype)
  
      if compress_image and len(shape) == 3 and dtype == tf.uint8:
  
          def _encode_to_jpeg_bytes_list(value):
              if shape[-1] == 1:
                  im = Image.fromarray(value[:, :, 0])
              else:
                  im = Image.fromarray(value)
              out = io.BytesIO()
              im.save(out, format="jpeg", quality=image_quality)
              return tf.train.Feature(
                  bytes_list=tf.train.BytesList(value=[out.getvalue()])
              )
  
          return _encode_to_jpeg_bytes_list
  
      if dtype == tf.float32:  # Serialize float32 to FloatList.
  
          def _encode_to_float_list(value):
              value = np.asarray(value)
              _check_shape_and_dtype(value, shape, dtype)
              return tf.train.Feature(
                  float_list=tf.train.FloatList(
                      value=value.flatten(order="C").tolist()
                  )
              )
  
          return _encode_to_float_list
      elif dtype == tf.int64:  # Serialize int64 to Int64List.
  
          def _encode_to_int64_list(value):
              value = np.asarray(value)
              _check_shape_and_dtype(value, shape, dtype)
              return tf.train.Feature(
                  int64_list=tf.train.Int64List(
                      value=value.flatten(order="C").tolist()
                  )
              )
  
          return _encode_to_int64_list
      else:  # Serialize anything else to BytesList in little endian order.
          le_dtype = dtype.as_numpy_dtype(0).newbyteorder("L")
  
          def _encode_to_bytes_list(value):
              value = np.asarray(value)
              _check_shape_and_dtype(value, shape, dtype)
              bytes_list_value = np.require(
                  value, dtype=le_dtype, requirements="C"
              ).tobytes()
              return tf.train.Feature(
                  bytes_list=tf.train.BytesList(
                      value=[bytes_list_value]
                  )
              )
  
          return _encode_to_bytes_list
  
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 7 for calling a global function with example usage: _get_feature_encoder(shape, dtype, compress_image, image_quality) and returns: _encode_to_jpeg_bytes_list, _encode_to_float_list, tf, tf, _encode_to_int64_list, _encode_to_bytes_list, tf, tf