python - 使用 tf.data.Dataset.from_generator 时为 "SystemError: error return without exception set"

标签 python tensorflow pycharm tensorflow-datasets

我在使用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

Check this post that offers more information

关于python - 使用 tf.data.Dataset.from_generator 时为 "SystemError: error return without exception set",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51615027/

相关文章:

python - 如何在pycharm中加载pcd文件

python - 使用 Python 循环除某些值外

tensorflow - 如何在 Keras 中使 LSTM 的初始状态可训练?

tensorflow - TensorFlow 中图像张量的形状是什么

python - 自动完成在虚拟环境pycharm中不起作用

Pandas 数据帧和 PyCharm IntelliSense

image - 这种裁剪算法更优雅的改写是什么? (在 Python 中)

python - Python mmap 和 multiprocessing.semaphore 的竞争条件

python - 扩展形式悄无声息地失败了

tensorflow - 将稀疏的 IndexedSlices 转换为密集的张量