Python 运行时错误:生成器在自定义培训Keras_Ocr时引发StopIteration

Python 运行时错误:生成器在自定义培训Keras_Ocr时引发StopIteration,python,tensorflow,ocr,Python,Tensorflow,Ocr,你好!我遵循这个模型来训练Keras_ocr模型,该模型实际上从图像中预测文本、数字和特殊符号。 我无法运行此代码,因为我在下面提到的代码部分遇到问题: data_dir=r'.' detector_batch_size = 1 detector_basepath = os.path.join(data_dir,'detector_{datetime.datetime.now().isoformat()}') detection_train_generator, detection_val_ge

你好!我遵循这个模型来训练Keras_ocr模型,该模型实际上从图像中预测文本、数字和特殊符号。 我无法运行此代码,因为我在下面提到的代码部分遇到问题:

data_dir=r'.'
detector_batch_size = 1
detector_basepath = os.path.join(data_dir,'detector_{datetime.datetime.now().isoformat()}')
detection_train_generator, detection_val_generator, detection_test_generator = [
    detector.get_batch_generator(
        image_generator=image_generator,
        batch_size=detector_batch_size
    ) for image_generator in image_generators
]

detector.model.fit_generator(
    generator=detection_train_generator,
    steps_per_epoch=math.ceil(len(background_splits[0]) / detector_batch_size),
    epochs=1000,
    workers=0,
    callbacks=[
        tf.keras.callbacks.EarlyStopping(restore_best_weights=True, patience=5),
        tf.keras.callbacks.CSVLogger('f{detector_basepath}.csv'),
        tf.keras.callbacks.ModelCheckpoint(filepath=f'{detector_basepath}.h5')
    ],
    validation_data=detection_val_generator,
    validation_steps=math.ceil(len(background_splits[1]) / detector_batch_size)
)
该代码中出现以下错误:

Epoch 1/1000
Traceback (most recent call last):

  File "C:\Anaconda3\lib\site-packages\keras_ocr\detection.py", line 633, in get_batch_generator
    batch = [next(image_generator) for n in range(batch_size)]

  File "C:\Anaconda3\lib\site-packages\keras_ocr\detection.py", line 633, in <listcomp>
    batch = [next(image_generator) for n in range(batch_size)]

StopIteration


The above exception was the direct cause of the following exception:

Traceback (most recent call last):

  File "D:\FYP Proposal\Generate Fonts and Backgrounds\Keras_Ocr_Training.py", line 117, in <module>
    validation_steps=math.ceil(len(background_splits[1]) / detector_batch_size)

  File "C:\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 1297, in fit_generator
    steps_name='steps_per_epoch')

  File "C:\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_generator.py", line 221, in model_iteration
    batch_data = _get_next_batch(generator)

  File "C:\Anaconda3\lib\site-packages\tensorflow_core\python\keras\engine\training_generator.py", line 363, in _get_next_batch
    generator_output = next(generator)

RuntimeError: generator raised StopIteration
1/1000纪元
回溯(最近一次呼叫最后一次):
文件“C:\Anaconda3\lib\site packages\keras\u ocr\detection.py”,第633行,在get\u batch\u生成器中
批次=[范围内n的下一个(图像\u生成器)(批次大小)]
文件“C:\Anaconda3\lib\site packages\keras\u ocr\detection.py”,第633行,在
批次=[范围内n的下一个(图像\u生成器)(批次大小)]
停止迭代
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“D:\FYP建议书\Generate Fonts and Backgrounds\Keras\u Ocr\u Training.py”,第117行,中
验证步骤=math.ceil(len(背景分割[1])/检测器批次大小)
文件“C:\Anaconda3\lib\site packages\tensorflow\u core\python\keras\engine\training.py”,第1297行,在fit\u生成器中
步骤(名称=“每个时代的步骤”)
文件“C:\Anaconda3\lib\site packages\tensorflow\u core\python\keras\engine\training\u generator.py”,第221行,在模型迭代中
批处理数据=\u获取\u下一批(生成器)
文件“C:\Anaconda3\lib\site packages\tensorflow\u core\python\keras\engine\training\u generator.py”,第363行,在下一批中
发电机输出=下一个(发电机)
运行时错误:生成器引发了StopIteration
任何人都可以帮助我解决此错误,提前感谢