class tf.io.TFRecordWriter
- __init__
__init__(
path,
options=None
)
path: 写入文件路径;
options: (可选)指定压缩类型TFRecordCompressionType,或TFRecordOptions对象的字符串 。
- 示例
writer = tf.io.TFRecordWriter("/path/output.tfrecords")
- close
#关闭文件
writer.close()
- flush
#刷新文件
writer.flush()
- write
#写入文件
writer.write(example_str)
tf.train.string_input_producer
- 用法
#输出字符串到一个输入管道队列
tf.train.string_input_producer(
string_tensor,
num_epochs=None,
shuffle=True,
seed=None,
capacity=32,
shared_name=None,
name=None,
cancel_op=None
)
string_tensor: 1-D字符串张量;
- 示例
filename_queue = tf.train.string_input_producer(
"/path/output.tfrecords")
tf.TRRecordReader
- __init__
__init__(
name=None,
options=None
)
- 示例
reader = tf.TFRecordReader()
- read
#从文件中读出一个样例
read(
queue,
name=None
)
queue: 队列;
serialized_example = reader.read(filename_queue)
- read_up_to
#从文件中一次性读取多个样例
read_up_to(
queue,
num_records,
name=None
)
num_records: 要读取的记录数;
- TFRecordDataset(新版本)
tf.parse_single_example
- 用法
#解析读入一个样例。多个样例,可以使用parse_example
parse_single_example(
serialized,
features,
name=None,
example_names=None
)
serialized:一个标量字符串张量,单个序列化的例子;
features:一个 dict,映射功能键到 FixedLenFeature 或 VarLenFeature值;
name:此操作的名称(可选);
example_names:(可选)标量字符串张量,关联的名称;
- 示例
features = tf.parse_single_example(
serializerd_example,
features={
'data_bytes': tf.FixedLenFeature([], tf.string),
'data_int': tf.FixedLenFeature([], tf.int64),
'data_float': tf.FixedLenFeature([], tf.float32),
}
)
tf.decode_raw
- 用法
decode_raw(
bytes,
out_type,
little_endian=True,
name=None
)
bytes: 要解析的字符串;
out_type: 解析原先的格式;
- 示例
image = tf.decode_raw(features['image_raw'], tf.uint8)
- tf.cast
label = tf.cast(features['label'], tf.int32)
网友评论