Tensorflow 读写 tfrecord 文件(Py3)
March 16, 2018, 10:28 p.m.
read: 971
写入tfrecord文件
import tensorflow as tf
file_path = ''
list = []
writer = tf.python_io.TFRecordWriter(file_path)
example = tf.train.Example(features=tf.train.Features(feature={
"label": tf.train.Feature(int64_list=tf.train.Int64List(value=list))
}))
writer.write(example.SerializeToString())
读取tfrecord文件
import tensorflow as tf
for serialized_example in tf.python_io.tf_record_iterator("文件的完整路径"):
example = tf.train.Example()
example.ParseFromString(serialized_example)
label = example.features.feature['label'].int64_list.value
# 可以做一些预处理之类的
print(label)