【问题标题】:How to parse a single TFrecord file如何解析单个 TFrecord 文件
【发布时间】:2017-03-22 08:44:08
【问题描述】:

读取 tfrecords:

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

TFRecordReader 从文件队列中读取示例。 但是如何同步地从特定文件中读取单个示例(没有队列)。喜欢

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

如何实现get_train_example函数

【问题讨论】:

  • 你能解释一下你试图用这个解决的问题吗?这可能有助于提出一个好的方法。
  • 我想要的只是直接解析 TFrecord 文件的一种方法。 TFRecordReader 在文件队列上工作。

标签: tensorflow file-format


【解决方案1】:

不确定这是否正是您要寻找的,但您可以通过这种方式进行操作,无需排队:

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)

【讨论】:

  • 对调试非常有用。
  • 这给出了 AttributeError: 'generator' object has no attribute 'next'
  • 如果您使用的是 python 3.x,则需要使用 next(...) 代替。
【解决方案2】:

用过这个

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

找到它here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 2017-07-12
    • 2020-02-21
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多