【问题标题】:tf.data.Dataset: Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter state is not initializedtf.data.Dataset:完成GeneratorDataset迭代器时发生错误:前置条件失败:Python解释器状态未初始化
【发布时间】:2021-07-19 18:31:43
【问题描述】:

我需要将基于Sequence 的数据生成器转换为tf.data.Dataset 格式。为此,我使用 from_generator 函数为我的所有训练、验证和测试数据创建重复的 BatchedDataset。

  dataset = tf.data.Dataset.from_generator(gen_function,
                                           output_signature=output_signature)
  dataset = dataset.shuffle(shuffle_buffer,
                            reshuffle_each_iteration=True)
  dataset = dataset.repeat()
  dataset = dataset.batch(batch_size)

这些用于模型拟合:

OCR.model.fit(x=training_generator,
              validation_data=validation_generator,
              steps_per_epoch=steps_per_epoch, 
              epochs=epochs,
              use_multiprocessing=True,
              callbacks=callbacks,
              workers=workers,
              verbose=verbose)

导致以下错误:

    /user/.../python3.8/site-packages/tensorflow/python/keras/engine/data_adapter.py, 
    line 739, in _validate_args raise ValueError(
    ValueError: When providing an infinite dataset, you must specify the number of 
    steps to run (if you did not intend to create an infinite dataset, make sure to 
    not call `repeat()` on the dataset).
    [date time]: W tensorflow/core/kernels/data/generator_dataset_op.cc:107] Error 
    occurred when finalizing GeneratorDataset iterator: Failed precondition: Python 
    interpreter state is not initialized. The process may be terminated.
    >· [[{{node PyFunc}}]]

这很令人困惑,因为我按照建议指定了重复无限数据集的步数。此外,当我之前使用基于序列的数据生成器时,它以这种方式与以这种方式指定的steps_per_epoch 一起工作。

【问题讨论】:

    标签: python tensorflow keras data-generation tf.data.dataset


    【解决方案1】:

    解决方法很简单,除了fit函数中的steps_per_epoch之外,只需要指定validation_steps参数即可。

    【讨论】:

    • 对不起,我遇到了同样的问题,但在此错误之前我得到了ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type dict). 2021-06-30 20:08:00.122545: W tensorflow/core/kernels/data/generator_dataset_op.cc:107] Error occurred when finalizing GeneratorDataset iterator: Failed precondition: Python interpreter state is not initialized. The process may be terminated.,这是否意味着我需要set validation_stepssteps_per_epoch?正如我设置的那样validation_steps =len(val_descriptions)
    • 我不确定你到底在做什么,我建议你提出一个新问题来详细说明你的方法。
    猜你喜欢
    • 1970-01-01
    • 2020-08-11
    • 2020-05-16
    • 2020-08-13
    • 1970-01-01
    • 2017-09-03
    • 2020-02-22
    • 1970-01-01
    • 2019-07-22
    相关资源
    最近更新 更多