我正在使用tensorflow后端在Keras中训练一个序列模型。我还包括了一些回调,以保存检查点,并在模型开始过度匹配时恢复到最佳权重(它会这样做)。
我的问题--当使用这组回调进行拟合时,最终的检查点是否包含具有最佳权重的模型版本?我知道classif_model中的权重将恢复,但我不确定这是否也适用于最终保存的状态。
from keras import callbacks as kc
classif_model = my_model(input_shape)
# Set up callbacks
checkpointer = kc.ModelCheckpoint(filepath='results/'+name+'.h5', verbose=0)
earlystopping = kc.EarlyStopping(monitor='val_loss', patience=patience, restore_best_weights = True)
callbacks = [checkpointer, earlystopping]
# train the model
hist = classif_model.fit(x = X_tr, y = Y_tr, epochs = epochs, batch_size = batch_size,
callbacks = callbacks, validation_data = (X_val, Y_val),
verbose = 0)发布于 2019-04-15 16:58:12
如果在检查点回调定义中设置save_best_only标志,它将:
ModelCheckpoint(filepath, monitor='val_loss', save_best_only=True)来自文档:
save_best_only:如果是save_best_only=True,根据所监控的数量,最新的最佳型号不会被覆盖。
https://datascience.stackexchange.com/questions/49333
复制相似问题