class_docstr: A class to write records to a TFRecords file.
  
  [TFRecords tutorial](https://www.tensorflow.org/tutorials/load_data/tfrecord)
  
  TFRecords is a binary format which is optimized for high throughput data
  retrieval, generally in conjunction with `tf.data`. `TFRecordWriter` is used
  to write serialized examples to a file for later consumption. The key steps
  are:
  
   Ahead of time:
  
   - [Convert data into a serialized format](
   https://www.tensorflow.org/tutorials/load_data/tfrecord#tfexample)
   - [Write the serialized data to one or more files](
   https://www.tensorflow.org/tutorials/load_data/tfrecord#tfrecord_files_in_python)
  
   During training or evaluation:
  
   - [Read serialized examples into memory](
   https://www.tensorflow.org/tutorials/load_data/tfrecord#reading_a_tfrecord_file)
   - [Parse (deserialize) examples](
   https://www.tensorflow.org/tutorials/load_data/tfrecord#reading_a_tfrecord_file)
  
  A minimal example is given below:
  
  >>> import tempfile
  >>> example_path = os.path.join(tempfile.gettempdir(), "example.tfrecords")
  >>> np.random.seed(0)
  
  >>> # Write the records to a file.
  ... with tf.io.TFRecordWriter(example_path) as file_writer:
  ...   for _ in range(4):
  ...     x, y = np.random.random(), np.random.random()
  ...
  ...     record_bytes = tf.train.Example(features=tf.train.Features(feature={
  ...         "x": tf.train.Feature(float_list=tf.train.FloatList(value=[x])),
  ...         "y": tf.train.Feature(float_list=tf.train.FloatList(value=[y])),
  ...     })).SerializeToString()
  ...     file_writer.write(record_bytes)
  
  >>> # Read the data back out.
  >>> def decode_fn(record_bytes):
  ...   return tf.io.parse_single_example(
  ...       # Data
  ...       record_bytes,
  ...
  ...       # Schema
  ...       {"x": tf.io.FixedLenFeature([], dtype=tf.float32),
  ...        "y": tf.io.FixedLenFeature([], dtype=tf.float32)}
  ...   )
  
  >>> for batch in tf.data.TFRecordDataset([example_path]).map(decode_fn):
  ...   print("x = {x:.4f},  y = {y:.4f}".format(**batch))
  x = 0.5488,  y = 0.7152
  x = 0.6028,  y = 0.5449
  x = 0.4237,  y = 0.6459
  x = 0.4376,  y = 0.8918
  
  This class implements `__enter__` and `__exit__`, and can be used
  in `with` blocks like a normal file. (See the usage example above.)
class_docstr_tok: ["A","class","to","write","records","to","a","TFRecords","file",".","[","TFRecords","tutorial","]","(","https",":","\/\/www.tensorflow.org\/tutorials\/load_data\/tfrecord",")","TFRecords","is","a","binary","format","which","is","optimized","for","high","throughput","data","retrieval",",","generally","in","conjunction","with","`","tf.data","`",".","`","TFRecordWriter","`","is","used","to","write","serialized","examples","to","a","file","for","later","consumption",".","The","key","steps","are",":","Ahead","of","time",":","-","[","Convert","data","into","a","serialized","format","]","(","https",":","\/\/www.tensorflow.org\/tutorials\/load_data\/tfrecord","#","tfexample",")","-","[","Write","the","serialized","data","to","one","or","more","files","]","(","https",":","\/\/www.tensorflow.org\/tutorials\/load_data\/tfrecord","#","tfrecord_files_in_python",")","During","training","or","evaluation",":","-","[","Read","serialized","examples","into","memory","]","(","https",":","\/\/www.tensorflow.org\/tutorials\/load_data\/tfrecord","#","reading_a_tfrecord_file",")","-","[","Parse","(","deserialize",")","examples","]","(","https",":","\/\/www.tensorflow.org\/tutorials\/load_data\/tfrecord","#","reading_a_tfrecord_file",")","A","minimal","example","is","given","below",":",">",">",">","import","tempfile",">",">",">","example_path","=","os.path.join","(","tempfile.gettempdir","(",")",",","``","example.tfrecords","''",")",">",">",">","np.random.seed","(","0",")",">",">",">","#","Write","the","records","to","a","file",".","...","with","tf.io.TFRecordWriter","(","example_path",")","as","file_writer",":","...","for","_","in","range","(","4",")",":","...","x",",","y","=","np.random.random","(",")",",","np.random.random","(",")","...","...","record_bytes","=","tf.train.Example","(","features=tf.train.Features","(","feature=","{","...","``","x","''",":","tf.train.Feature","(","float_list=tf.train.FloatList","(","value=","[","x","]",")",")",",","...","``","y","''",":","tf.train.Feature","(","float_list=tf.train.FloatList","(","value=","[","y","]",")",")",",","...","}",")",")",".SerializeToString","(",")","...","file_writer.write","(","record_bytes",")",">",">",">","#","Read","the","data","back","out",".",">",">",">","def","decode_fn","(","record_bytes",")",":","...","return","tf.io.parse_single_example","(","...","#","Data","...","record_bytes",",","...","...","#","Schema","...","{","``","x","''",":","tf.io.FixedLenFeature","(","[","]",",","dtype=tf.float32",")",",","...","``","y","''",":","tf.io.FixedLenFeature","(","[","]",",","dtype=tf.float32",")","}","...",")",">",">",">","for","batch","in","tf.data.TFRecordDataset","(","[","example_path","]",")",".map","(","decode_fn",")",":","...","print","(","``","x","=","{","x",":",".4f","}",",","y","=","{","y",":",".4f","}","''",".format","(","*","*","batch",")",")","x","=","0.5488",",","y","=","0.7152","x","=","0.6028",",","y","=","0.5449","x","=","0.4237",",","y","=","0.6459","x","=","0.4376",",","y","=","0.8918","This","class","implements","`","__enter__","`","and","`","__exit__","`",",","and","can","be","used","in","`","with","`","blocks","like","a","normal","file",".","(","See","the","usage","example","above",".",")"]
docstr: Opens file `path` and creates a `TFRecordWriter` writing to it.
  
  Args:
    path: The path to the TFRecords file.
    options: (optional) String specifying compression type,
        `TFRecordCompressionType`, or `TFRecordOptions` object.
  
  Raises:
    IOError: If `path` cannot be opened for writing.
    ValueError: If valid compression_type can't be determined from `options`.
docstr_tok: ["Opens","file","`","path","`","and","creates","a","`","TFRecordWriter","`","writing","to","it",".","Args",":","path",":","The","path","to","the","TFRecords","file",".","options",":","(","optional",")","String","specifying","compression","type",",","`","TFRecordCompressionType","`",",","or","`","TFRecordOptions","`","object",".","Raises",":","IOError",":","If","`","path","`","can","not","be","opened","for","writing",".","ValueError",":","If","valid","compression_type","ca","n't","be","determined","from","`","options","`","."]
code: def __init__(self, path, options=None):
      """Opens file `path` and creates a `TFRecordWriter` writing to it.
  
      Args:
        path: The path to the TFRecords file.
        options: (optional) String specifying compression type,
            `TFRecordCompressionType`, or `TFRecordOptions` object.
  
      Raises:
        IOError: If `path` cannot be opened for writing.
        ValueError: If valid compression_type can't be determined from `options`.
      """
      if not isinstance(options, TFRecordOptions):
          options = TFRecordOptions(compression_type=options)
  
      # pylint: disable=protected-access
      super(TFRecordWriter, self).__init__(
          compat.as_bytes(path), options._as_record_writer_options()
      )
  
file_path: tensorflow/tensorflow/python/lib/io/tf_record.py
imports: from tensorflow.python.lib.io import _pywrap_record_io
  from tensorflow.python.util import compat
  from tensorflow.python.util import deprecation
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 1 to create a new TFRecordWriter object from inherited base classes: _pywrap_record_io with example: obj = TFRecordWriter(path, options)