当前位置: 代码迷 >> 综合 >> ValueError: steps_per_epoch=None is only valid for a generator based on the keras.utils.Sequence
  详细解决方案

ValueError: steps_per_epoch=None is only valid for a generator based on the keras.utils.Sequence

热度:94   发布时间:2023-12-02 09:06:06.0

ValueError: steps_per_epoch=None is only valid for a generator based on the keras.utils.Sequence

https://github.com/keras-team/keras/tree/master/examples

运行如上代码cifar10_resnet.py文件出现下列错误

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.

只需要把

model.fit_generator(datagen.flow(x_train, y_train, batch_size=batch_size),
validation_data=(x_test, y_test),
epochs=epochs, verbose=1, workers=4,
callbacks=callbacks)

换成

model.fit_generator(datagen.flow(x_train, y_train, batch_size=batch_size),
steps_per_epoch=x_train.shape[0] // batch_size,
validation_data=(x_test, y_test),
epochs=epochs, verbose=1, workers=4,
callbacks=callbacks)

  相关解决方案