tf.io.TFRecordWriter
Stay organized with collections
Save and categorize content based on your preferences.
A class to write records to a TFRecords file.
tf.io.TFRecordWriter(
path, options=None
)
This class implements __enter__
and __exit__
, and can be used
in with
blocks like a normal file.
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 .
|
Methods
close
View source
close()
Close the file.
flush
View source
flush()
Flush the file.
write
View source
write(
record
)
Write a string record to the file.
__enter__
View source
__enter__()
Enter a with
block.
__exit__
View source
__exit__(
unused_type, unused_value, unused_traceback
)
Exit a with
block, closing the file.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.io.TFRecordWriter\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 2 version](/api_docs/python/tf/io/TFRecordWriter) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/lib/io/tf_record.py#L192-L246) |\n\nA class to write records to a TFRecords file.\n\n#### View aliases\n\n\n**Main aliases**\n\n\\`tf.python_io.TFRecordWriter\\`\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.io.TFRecordWriter`](/api_docs/python/tf/io/TFRecordWriter), [`tf.compat.v1.python_io.TFRecordWriter`](/api_docs/python/tf/io/TFRecordWriter), \\`tf.compat.v2.io.TFRecordWriter\\`\n\n\u003cbr /\u003e\n\n tf.io.TFRecordWriter(\n path, options=None\n )\n\nThis class implements `__enter__` and `__exit__`, and can be used\nin `with` blocks like a normal file.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------|--------------------------------------------------------------------------------------------------------|\n| `path` | The path to the TFRecords file. |\n| `options` | (optional) String specifying compression type, `TFRecordCompressionType`, or `TFRecordOptions` object. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|---------------------------------------------------------------|\n| `IOError` | If `path` cannot be opened for writing. |\n| `ValueError` | If valid compression_type can't be determined from `options`. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `close`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/lib/io/tf_record.py#L243-L246) \n\n close()\n\nClose the file.\n\n### `flush`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/lib/io/tf_record.py#L238-L241) \n\n flush()\n\nFlush the file.\n\n### `write`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/lib/io/tf_record.py#L229-L236) \n\n write(\n record\n )\n\nWrite a string record to the file.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------|-----|\n| `record` | str |\n\n\u003cbr /\u003e\n\n### `__enter__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/lib/io/tf_record.py#L221-L223) \n\n __enter__()\n\nEnter a `with` block.\n\n### `__exit__`\n\n[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/lib/io/tf_record.py#L225-L227) \n\n __exit__(\n unused_type, unused_value, unused_traceback\n )\n\nExit a `with` block, closing the file."]]