`steps_per_epoch=None` 仅对基于 `keras.utils.Sequence` 的生成器有效

Sim*_*GIS 2 python tensorflow

我在张量流中运行此代码:https://github.com/empathy87/nn-grocery-shelves/blob/master/Step%202%20-%20Brands%20Recognition%20with%20CNN.ipynb

batch_size = 50
epochs = 15
model.fit_generator(datagen.flow(x_train, y_train, batch_size=batch_size),
                    validation_data=(x_validation, y_validation),
                    epochs=epochs, verbose=1, workers=4, 
                    callbacks=[LearningRateScheduler(lr_schedule)])

ValueError: `steps_per_epoch=None` is only valid for a generator based on the `keras.utils.Sequence` class. Please specify `steps_per_epoch` or use the `keras.utils.Sequence` class.
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?我尝试在 Pip install tensorflow 和 conda install tensorflow 中重新安装 Tensosflow。

gmd*_*mds 5

原因是创建的对象datagen.flow不知道其大小,因此您应该指定它预期产生值的次数,您可以结合批量大小来计算该值。

假设您有 100 个训练点,并且想要使用 30 的批量大小。那么,每个 epoch 需要 4 个步骤,计算方式如下:

from math import ceil

n_points = len(X_train)
batch_size = 30

steps_per_epoch = ceil(n_points / batch_size)
Run Code Online (Sandbox Code Playgroud)