RuntimeError: __iter__() is only supported inside of tf.function or when eager execution is enabled.
https://stackoverflow.com/questions/63182524/runtimeerror-iter-is-only-supported-inside-of-tf-function-or-when-eager-e 访问时间 2023/3/19.¹ 你可以参考这里的文档来学习如何使用tf.data.Dataset API。你的代码出现了一个运行时错误,提示你只能在tf.fun
RuntimeError Traceback (most recent call last)
in
1 ds = make_input_fn(dftrain, y_train, batch_size=10)()
----> 2 for feature_batch, label_batch in ds.take(1):
3 print(‘Some feature keys:’, list(feature_batch.keys()))
4 print()
5 print(‘A batch of class:’, feature_batch[‘class’].numpy())
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/data/ops/dataset_ops.py in iter(self)
2032
2033 def iter(self):
-> 2034 return iter(self._dataset)
2035
2036
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/data/ops/dataset_ops.py in iter(self)
341 return iterator_ops.IteratorV2(self)
342 else:
–> 343 raise RuntimeError("iter() is only supported inside of tf.function "
344 “or when eager execution is enabled.”)
345
RuntimeError: iter() is only supported inside of tf.function or when eager execution is enabled.
你的代码出现了一个运行时错误,提示你只能在tf.function或者开启了eager execution的情况下使用__iter__()方法。¹²³
这个错误可能是因为你没有正确地使用tf.data.Dataset API来创建和处理数据集。¹ 你可以参考这里的文档来学习如何使用tf.data.Dataset API。
你也可以尝试在你的代码前面(一定要在文件的最开头)加上以下两行来强制开启eager execution模式:
import tensorflow as tf
tf.compat.v1.enable_eager_execution()
这样可能可以解决你的问题。²
2023/3/19(1) RuntimeError: iter() is only supported inside of tf.function or … https://stackoverflow.com/questions/63182524/runtimeerror-iter-is-only-supported-inside-of-tf-function-or-when-eager-e 访问时间 2023/3/19.
(2) TensorFlow 2.0 dataset.iter() is only supported when eager … https://stackoverflow.com/questions/55576133/tensorflow-2-0-dataset-iter-is-only-supported-when-eager-execution-is-enab 访问时间 2023/3/19.
(3) iter() is only supported inside of tf.function or when eager … https://github.com/tensorflow/tensorflow/issues/51076 访问时间 2023/3/19.
更多推荐


所有评论(0)