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: If not in py_mode Wraps write() into a TF op for eager execution.
docstr_tok: ["If","not","in","py_mode","Wraps","write","(",")","into","a","TF","op","for","eager","execution","."]
code: def __call__(self, data):
      """If not in py_mode Wraps write() into a TF op for eager execution."""
      if self._py_mode:
          self.write(data)
      else:
          flat_data = tf.nest.flatten(data)
          tf.numpy_function(
              self.write, flat_data, [], name="encoder_observer"
          )
  
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 5 for calling the TFRecordObserver obj's underlying member method code with example usage: obj.__call__(data) without return types