#127022·tensorflow

启动垃圾收集时调试模式中的“ dataset. from generator” 出错

作者: stinodego创建于 2026年9月8日更新于 2026年9月17日
标签stat:contribution welcometype:bugcomp:data2.21.0
import gc
import tensorflow as tf
tf.data.experimental.enable_debug_mode()

def generator():
    yield 1
    yield 2
dataset = tf.data.Dataset.from_generator(
    generator, output_signature=tf.TensorSpec(shape=(), dtype=tf.int64)
)
iterator = iter(dataset)
print("first:", next(iterator).numpy())
gc.collect()
print("second:", next(iterator).numpy())  # ValueError: Could not find callback ...

内容来源: tensorflow/tensorflow