Tensorflow 读写 tfrecord 文件(Python3)

时间:2019-03-13 11:23:14   收藏:0   阅读:339

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

原文:https://www.cnblogs.com/LewisLEO/p/10521695.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!