Parsing TFRecord when in eager execution

半城伤御伤魂 提交于 2019-12-24 08:25:09

问题


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).


回答1:


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

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)

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

Hope that helps.



来源:https://stackoverflow.com/questions/49989406/parsing-tfrecord-when-in-eager-execution

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