我需要将我的数据生成器转换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
此外,当我之前使用基于序列的数据生成器时,它以这种方式与指定的方式一起工作。