我正在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.
如何解决此问题?我试图在Pip install tensorflow和conda install tensorflow中重新安装Tensosflow。
答案 0 :(得分:1)
原因是datagen.flow
创建的对象不知道其大小,因此,您应该指定期望它产生多少次值,可以结合批处理进行计算大小。
假设您有100个训练点,并且希望以30个批次进行工作。那么,每个纪元将有4个步骤,按以下方式计算:
from math import ceil
n_points = len(X_train)
batch_size = 30
steps_per_epoch = ceil(n_points / batch_size)