我正在使用keras.preprocessing.image.ImageDataGenerator
当我像这样将其输入到model.fit
时
history = model.fit( train_data_gen, epochs=EPOCHS, steps_per_epoch=steps_per_epoch, validation_data=val_data_gen, validation_freq=validation_freq, callbacks=[EarlyStopping(monitor='val_accuracy', patience=2)])
运行正常,但实际上没有验证数据,因此我的回调函数无法工作,绘图也无法进行,因为history.history['val_accuracy']
根本不存在,我在这个字典中只有两个项目:accuracy和loss
所以我的主要问题是如何让它像这样工作
history = model.fit( x=train_data_gen, y=val_data_gen,)
但没有
ValueError: `y` argument is not supported when using python generator as input.
回答:
问题出在model.fit
的参数上
validation_freq=validation_freq
应改为validation_steps=validation_freq
这样之后一切正常运行,val_accuracy
终于可用
history = model.fit( x=train_data_gen, epochs=EPOCHS, steps_per_epoch=steps_per_epoch, validation_data=val_data_gen, validation_steps=validation_freq, callbacks=[ EarlyStopping(monitor='val_accuracy', patience=2), ModelCheckpoint('models/m-{epoch:02d}-{val_accuracy:.4f}.h5') ],).history