目录
Python functions for directly manipulating TFRecord-formatted files.
Classes
- class TFRecordCompressionType: The type of compression for the record.
- class TFRecordOptions: Options used for manipulating TFRecord files.
- class TFRecordWriter: A class to write records to a TFRecords file.
Functions
- tf_record_iterator(...): An iterator that read the records from a TFRecords file. (deprecated)
tf.io.TFRecordCompressionType
Class TFRecordCompressionType
The type of compression for the record.
Aliases:
- Class tf.compat.v1.io.TFRecordCompressionType
- Class tf.compat.v1.python_io.TFRecordCompressionType
- Class tf.python_io.TFRecordCompressionType
Class Members
Class TFRecordOptions
Options used for manipulating TFRecord files.
Aliases:
- Class tf.compat.v1.io.TFRecordOptions
- Class tf.compat.v1.python_io.TFRecordOptions
- Class tf.compat.v2.io.TFRecordOptions
- Class tf.python_io.TFRecordOptions
__init__
__init__(
compression_type=None,
flush_mode=None,
input_buffer_size=None,
output_buffer_size=None,
window_bits=None,
compression_level=None,
compression_method=None,
mem_level=None,
compression_strategy=None
)
Creates a TFRecordOptions
instance.
Options only effect TFRecordWriter when compression_type is not None
. Documentation, details, and defaults can be found in zlib_compression_options.h and in the zlib manual. Leaving an option as None
allows C++ to set a reasonable default.
Args:
compression_type
:"GZIP"
,"ZLIB"
, or""
(no compression).flush_mode
: flush mode orNone
, Default: Z_NO_FLUSH.input_buffer_size
: int orNone
.output_buffer_size
: int orNone
.window_bits
: int orNone
.compression_level
: 0 to 9, orNone
.compression_method
: compression method orNone
.mem_level
: 1 to 9, orNone
.compression_strategy
: strategy orNone
. Default: Z_DEFAULT_STRATEGY.
Returns:
- A
TFRecordOptions
object.
Raises:
ValueError
: If compression_type is invalid.
Methods
get_compression_type_string
@classmethod
get_compression_type_string(
cls,
options
)
Convert various option types to a unified string.
Args:
options
:TFRecordOption
,TFRecordCompressionType
, or string.
Returns:
- Compression type as string (e.g.
'ZLIB'
,'GZIP'
, or''
).
Raises:
ValueError
: If compression_type is invalid.
Class Members
compression_type_map
TFRecordWriter
将记录写入TFRecords文件的类。这个类实现了_enter__和_exit__,可以像普通文件一样与块一起使用。
方法:
__init__
__init__(
path,
options=None
)
打开文件路径并创建一个TFRecordWriter写入文件。
参数:
- path: TFRecords文件的路径。
options
: (可选)TFRecordOptions对象。
可能产生的异常:
IOError
: Ifpath
cannot be opened for writing.
__enter__
__enter__()
输入一个block。
__exit__
__exit__(
unused_type,
unused_value,
unused_traceback
)
退出bloack,关闭文件。
close
close()
flush
flush()
刷新文件。
write
write(record)
向文件中写入字符串记录。
参数:
- record: str
tf.io.tf_record_iterator
An iterator that read the records from a TFRecords file. (deprecated)
Aliases:
- tf.compat.v1.io.tf_record_iterator
- tf.compat.v1.python_io.tf_record_iterator
- tf.python_io.tf_record_iterator
tf.io.tf_record_iterator(
path,
options=None
)
Warning: THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use eager execution and: tf.data.TFRecordDataset(path)
Args:
path
: The path to the TFRecords file.options
: (optional) A TFRecordOptions object.
Yields:
- Strings.
Raises:
IOError
: Ifpath
cannot be opened for reading.