class_docstr: File writer for TFRecord dataset.
  
  TFRecordWriter serializes tensors in tf.Example schema and write them
  into files in TFRecord format. The written file can be loaded with
  tf.data.TFRecordDataset.
class_docstr_tok: ["File","writer","for","TFRecord","dataset",".","TFRecordWriter","serializes","tensors","in","tf.Example","schema","and","write","them","into","files","in","TFRecord","format",".","The","written","file","can","be","loaded","with","tf.data.TFRecordDataset","."]
docstr: Create tf.Example parser function based on the data_source.
  
  The parser function can be used for parsing tf.Example.
  Example usage:
  
  ``` python
  data_source = DataSource(...)
  with TFRecordWriter() as writer:
      dir_path = writer.write(data_source)
      parser_fn = writer.create_tf_example_parser_fn(data_source)
  
      pattern = os.path.join(dir_path, f"*.{writer.extension}")
      dataset = tf.data.Dataset.list_files(pattern)
      dataset = tf.data.TFRecordDataset(dataset)
      dataset = dataset.map(parser_fn)
  ```
  
  Args:
    data_source: A DataSource object describe the format of the data.
    with_batch: True if the parser function should take a number of
                serialized tf.Example proto. Default is false.
  
  Returns:
    A callable function that takes serialized tf.Example proto as input,
    and returns the parsed tensor dict.
docstr_tok: ["Create","tf.Example","parser","function","based","on","the","data_source",".","The","parser","function","can","be","used","for","parsing","tf.Example",".","Example","usage",":","``","`","python","data_source","=","DataSource","(","...",")","with","TFRecordWriter","(",")","as","writer",":","dir_path","=","writer.write","(","data_source",")","parser_fn","=","writer.create_tf_example_parser_fn","(","data_source",")","pattern","=","os.path.join","(","dir_path",",","f","''","*",".","{","writer.extension","}","''",")","dataset","=","tf.data.Dataset.list_files","(","pattern",")","dataset","=","tf.data.TFRecordDataset","(","dataset",")","dataset","=","dataset.map","(","parser_fn",")","``","`","Args",":","data_source",":","A","DataSource","object","describe","the","format","of","the","data",".","with_batch",":","True","if","the","parser","function","should","take","a","number","of","serialized","tf.Example","proto",".","Default","is","false",".","Returns",":","A","callable","function","that","takes","serialized","tf.Example","proto","as","input",",","and","returns","the","parsed","tensor","dict","."]
code: def create_tf_example_parser_fn(self, data_source, with_batch=False):
      """Create tf.Example parser function based on the data_source.
  
      The parser function can be used for parsing tf.Example.
      Example usage:
  
      ``` python
      data_source = DataSource(...)
      with TFRecordWriter() as writer:
          dir_path = writer.write(data_source)
          parser_fn = writer.create_tf_example_parser_fn(data_source)
  
          pattern = os.path.join(dir_path, f"*.{writer.extension}")
          dataset = tf.data.Dataset.list_files(pattern)
          dataset = tf.data.TFRecordDataset(dataset)
          dataset = dataset.map(parser_fn)
      ```
  
      Args:
        data_source: A DataSource object describe the format of the data.
        with_batch: True if the parser function should take a number of
                    serialized tf.Example proto. Default is false.
  
      Returns:
        A callable function that takes serialized tf.Example proto as input,
        and returns the parsed tensor dict.
      """
      scenario = data_source.scenario
      feature_description = {
          name: self._build_tf_example_parsing_config(
              name, scenario[name]
          )
          for name in scenario
      }
  
      if with_batch:
  
          def _batch_examples_parser_fn(example_proto):
              return tf.io.parse_example(
                  example_proto, feature_description
              )
  
          return _batch_examples_parser_fn
  
      def _single_example_parser_fn(example_proto):
          return tf.io.parse_single_example(
              example_proto, feature_description
          )
  
      return _single_example_parser_fn
  
file_path: io/tests/test_atds_avro/utils/tf_record_writer.py
imports: import os
  from tests.test_atds_avro.utils.generator.tensor_generator import TensorGeneratorBase
  from tests.test_atds_avro.utils.generator.sparse_tensor_generator import SparseTensorGeneratorBase
  from tests.test_atds_avro.utils.generator.varlen_tensor_generator import VarLenTensorGeneratorBase
  import numpy
  import tensorflow
  from tests.test_atds_avro.utils.file_writer import FileWriter
label_desc: Use image node_id 9 for calling the TFRecordWriter obj's underlying member method code with example usage: obj.create_tf_example_parser_fn(data_source, with_batch) and returns: _single_example_parser_fn, _batch_examples_parser_fn, tf, tf