gpt4 book ai didi

python - Keras 回调 ModelCheckpoint 不保存权重

转载 作者:行者123 更新时间:2023-12-04 01:00:24 25 4
gpt4 key购买 nike

这里建议的解决方案没有解决我的问题this question .

我正在尝试使用回调 ModelCheckpoint 和 EarlyStopping 在提前停止时保存最佳权重。在第一个纪元之后,我收到运行时警告,但代码运行剩余的纪元没有错误,但仍然没有包含权重的文件出现。第一个纪元后的警告如下:

RuntimeWarning: Can save best model only with val_acc available, skipping. 'skipping.' % (self.monitor), RuntimeWarning) RuntimeWarning: Early stopping conditioned on metric val_acc which is not available. Available metrics are: val_loss,val_accuracy,loss,accuracy (self.monitor, ','.join(list(logs.keys()))), RuntimeWarning

我在 fit() 函数中添加了验证数据,所以我不确定为什么。

filepath = "weights_best.hdf5"

model.compile(loss="mean_squared_error",
metrics=['accuracy'],
optimizer=optimizer)
batchSize = 64
numEpochs = 75
validation_data = (data.x_valid, data.y_valid)

callbackCheckpoint = keras.callbacks.callbacks.ModelCheckpoint(filepath,
monitor='val_acc',
save_best_only=True,
save_weights_only= True,
mode='max')

callbackEarlyStop = keras.callbacks.callbacks.EarlyStopping(monitor='val_acc',
min_delta=0,
patience=7,
verbose=0,
mode='auto')
callbacks = [callbackCheckpoint, callbackEarlyStop]
model.fit(data.x_train, data.y_train, batchSize, numEpochs, callbacks=callbacks,
validation_data=validation_data)

如有任何帮助,我们将不胜感激!

最佳答案

monitor='val_acc' 更改为 monitor='val_accuracy' 或将 metrics=['accuracy'] 更改为 metrics= ['acc']

关于python - Keras 回调 ModelCheckpoint 不保存权重,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58682098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com