Tensorflow 读写 tfrecord 文件(Python3)

TensorFlow笔记博客:https://blog.csdn.net/xierhacker/article/category/6511974

写入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)

https://blog.csdn.net/huplion/article/details/79600219

猜你喜欢

转载自www.cnblogs.com/LewisLEO/p/10521695.html