在2018年TensorFlow开发者峰会的tf.data演讲中,Derek Murray提出了一种将tf.dataAPI与TensorFlow的急切执行模式相结合的方法(10:54).我尝试了那里显示的代码的简化版本:
import tensorflow as tf
tf.enable_eager_execution()
dataset = tf.data.Dataset.from_tensor_slices(tf.random_uniform([50, 10]))
dataset = dataset.batch(5)
for batch in dataset:
print(batch)
Run Code Online (Sandbox Code Playgroud)
造成
TypeError: 'BatchDataset' object is not iterable
Run Code Online (Sandbox Code Playgroud)
我也尝试使用dataset.make_one_shot_iterator()和dataset.make_initializable_iterator()迭代数据集,但它们导致了
RuntimeError: dataset.make_one_shot_iterator is not supported when eager execution is enabled.
Run Code Online (Sandbox Code Playgroud)
和
RuntimeError: dataset.make_initializable_iterator is not supported when eager execution is enabled.
Run Code Online (Sandbox Code Playgroud)
TensorFlow版本:1.7.0,Python版本:3.6
如何在tf.data急切的执行中使用API?