在急切执行时解析 TFRecord [英] Parsing TFRecord when in eager execution

查看:48
本文介绍了在急切执行时解析 TFRecord的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到可以在急切执行模式下运行 tf.Data.Datasets,我应该如何在急切执行时打开 TFRecord 文件?我更关心解析器的编写,因为我目前使用 dataset.make_one_shot_iterator 作为迭代器(在容器上的多个图像之间).

Considering that is possible to run tf.Data.Datasets in eager execution mode, how should I open a TFRecord file on eager execution? I'm more concerned about the parser writing, because I'm currently using dataset.make_one_shot_iterator as an iterator (between several images on my container).

推荐答案

在 TensorFlow 1.8 及更高版本中,您可以自然地迭代 tf.data.Dataset 对象并启用急切执行.

In TensorFlow 1.8 onwards you can naturally iterate on the tf.data.Dataset object with eager execution enabled.

ds = tf.data.TFRecordDataset(...).map(...).batch(...)
for x in ds:
  print(x)

make_one_shot_iterator 也可以工作(继续工作以保持与图构造的等效代码兼容):

make_one_shot_iterator will also work (kept working to keep compatible with equivalent code for graph construction):

ds = tf.data.TFRecordDataset(...).map(...).batch(...)
itr = ds.make_one_shot_iterator()
for x in itr:
  print(x)

但是,在旧版本的 TensorFlow 中(其中 Eager Execution 是一个新引入的功能,因此不太成熟),您必须将数据集包装在 tf.contrib.eager.Iterator 中,使用类似的东西:

However, in older versions of TensorFlow (where eager execution is a newly introduced feature and thus less baked), you'll have to wrap your dataset in a tf.contrib.eager.Iterator, using something like:

tfe  tf.contrib.eager
ds = tf.data.TFRecordDataset(...).map(...).batch(...)
for x in tfe.Iterator(ds):
  print(x)

查看与 1.7 版本相关的这些资源:- 笔记本-

See these resources associated with the 1.7 release: - Notebook - RNN example

希望有所帮助.

这篇关于在急切执行时解析 TFRecord的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆