如何从ImageDataGenerator中获取history[‘val_accuracy’]

我正在使用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

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注