class_docstr: Observer for writing experience to TFRecord file.
  
  To use this observer, create an instance using a trajectory spec object
  and a dataset path:
  
  trajectory_spec = agent.collect_data_spec
  dataset_path = '/tmp/my_example_dataset'
  tfrecord_observer = TFRecordObserver(dataset_path, trajectory_spec)
  
  Then add it to the observers kwarg for the driver:
  
  collect_op = MyDriver(
    ...
    observers=[..., tfrecord_observer],
    num_steps=collect_steps_per_iteration).run()
  
  *Note*: Depending on your driver you may have to do
    `common.function(tfrecord_observer)` to handle the use of a callable with no
    return within a `tf.group` operation.
docstr: Creates observer object.
  
  Args:
    output_path: The path to the TFRecords file.
    tensor_data_spec: Nested list/tuple or dict of TensorSpecs, describing the
      shape of the non-batched Tensors.
    py_mode: Whether the observer is being used in a py_driver.
    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).
  
  Raises:
    ValueError: if the tensors and specs have incompatible dimensions or
    shapes.
docstr_tok: ["Creates","observer","object",".","Args",":","output_path",":","The","path","to","the","TFRecords","file",".","tensor_data_spec",":","Nested","list\/tuple","or","dict","of","TensorSpecs",",","describing","the","shape","of","the","non-batched","Tensors",".","py_mode",":","Whether","the","observer","is","being","used","in","a","py_driver",".","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",")",".","Raises",":","ValueError",":","if","the","tensors","and","specs","have","incompatible","dimensions","or","shapes","."]
code: def __init__(
      self,
      output_path,
      tensor_data_spec,
      py_mode=False,
      compress_image=False,
      image_quality=95,
  ):
      """Creates observer object.
  
      Args:
        output_path: The path to the TFRecords file.
        tensor_data_spec: Nested list/tuple or dict of TensorSpecs, describing the
          shape of the non-batched Tensors.
        py_mode: Whether the observer is being used in a py_driver.
        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).
  
      Raises:
        ValueError: if the tensors and specs have incompatible dimensions or
        shapes.
      """
      self._py_mode = py_mode
      self._array_data_spec = tensor_spec.to_nest_array_spec(
          tensor_data_spec
      )
      self._encoder = example_encoding.get_example_serializer(
          self._array_data_spec,
          compress_image=compress_image,
          image_quality=image_quality,
      )
      # Two output files: a tfrecord file and a file with the serialized spec
      self.output_path = output_path
      tf.io.gfile.makedirs(os.path.dirname(self.output_path))
      self._writer = tf.io.TFRecordWriter(self.output_path)
      logging.info(
          "Writing dataset to TFRecord at %s", self.output_path
      )
      # Save the tensor spec used to write the dataset to file
      spec_output_path = self.output_path + _SPEC_FILE_EXTENSION
      encode_spec_to_file(spec_output_path, tensor_data_spec)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  from absl import logging
  import tensorflow
  from tf_agents.specs import tensor_spec
  from tf_agents.trajectories import trajectory
  from tf_agents.utils import eager_utils
  from tf_agents.utils import example_encoding
  from tf_agents.utils import nest_utils
  from tensorflow.core.protobuf import struct_pb2
label_desc: Use image node_id 1 to create a new TFRecordObserver object from inherited base classes: object with example: obj = TFRecordObserver(output_path, tensor_data_spec, py_mode, compress_image, image_quality)