我在使用tf.data.Dataset.from_generator
时遇到了奇怪的运行时错误。
import tensorflow as tf
def gen():
while True:
yield 0, 0
batch = (
tf.data.Dataset.from_generator(
gen, output_types=(tf.int32, tf.int32))
.batch(8)
.repeat()
.make_one_shot_iterator()
.get_next()
)
sess = tf.InteractiveSession()
sess.run(batch)
会打印这样的消息
Exception ignored in: <generator object _yield_value at 0x000001FD9ED6A7D8>
Traceback (most recent call last):
File "C:\Users\user209974\AppData\Local\Continuum\miniconda3\envs\tf\lib\site-packages\tensorflow\python\data\util\nest.py", line 100, in _yield_value
yield value
SystemError: error return without exception set
调用 Session.run
时会在运行时抛出错误,显然是每次调用生成器时。但奇怪的是,尽管抛出了这个错误,但返回的值似乎是正确的。
那么是什么导致了这个错误以及如何消除它呢? (出于某种原因,删除批处理或在 gen
中返回单个值会使错误消失)。
编辑
我意识到在 PyCharm 下以 Debug模式运行时会出现这些错误。如果我在 python 控制台中作为脚本运行代码,或者在 PyCharm 中但不在 Debug模式下运行代码,则不会打印这些消息。
最佳答案
这似乎是 Pycharm 的问题。解决方案是在 pycharm 设置中设置此环境变量:
PYDEVD_USE_FRAME_EVAL=NO
关于python - 使用 tf.data.Dataset.from_generator 时为 "SystemError: error return without exception set",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51615027/