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","."]
code: def _write_to_path_from_cached_data(
      self, dir_path, data_source, dataset
  ):
      if os.path.exists(dir_path):
          return dir_path
      os.makedirs(dir_path)
  
      scenario = data_source.scenario
      filenames_to_num_records = self._get_filenames_to_num_records(
          data_source
      )
      iterator = iter(dataset)
      for filename in sorted(filenames_to_num_records):
          file_path = os.path.join(dir_path, filename)
          num_records = filenames_to_num_records[filename]
  
          with tf.io.TFRecordWriter(file_path) as file_writer:
              for _ in range(num_records):
                  features = {}
                  record = iterator.get_next()
  
                  for feature_name in scenario:
                      generator = scenario[feature_name]
                      feature = record[feature_name]
                      self._add_tensor_to_features(
                          generator, feature_name, feature, features
                      )
                  record_bytes = tf.train.Example(
                      features=tf.train.Features(feature=features)
                  ).SerializeToString()
                  file_writer.write(record_bytes)
  
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 4 for calling the TFRecordWriter obj's underlying member method code with example usage: obj._write_to_path_from_cached_data(dir_path, data_source, dataset) and returns: dir_path