How to parse a single TFrecord file

我们两清 提交于 2019-12-12 04:20:01

问题


To read tfrecords:

reader = tf.TFRecordReader()
_, serialized_example = reader.read(filename_queue)
features = tf.parse_single_example(...)

TFRecordReader reads examples from a file queue. But how to read a single example from a particular file synchronically(without a queue). like

file_buf = tf.read_file(filename)
serialized_example = get_train_example(file_buf)
features = tf.parse_single_example(...)

how to implement the get_train_example function


回答1:


Not sure if this exactly what you're looking for, but you can do it this way without a queue:

tf_record = "path/to/my.tfrecord"
e = tf.python_io.tf_record_iterator(tf_record).next()
single_example = tf.parse_single_example(e, features=features)



回答2:


used this one

for example in tf.python_io.tf_record_iterator("path_to_your_file"):
    result = tf.train.Example.FromString(example)
print(result)

found it here



来源:https://stackoverflow.com/questions/42946547/how-to-parse-a-single-tfrecord-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!