Validation 如果给出验证数据,Keras如何选择最终模型?

Validation 如果给出验证数据,Keras如何选择最终模型?,validation,machine-learning,keras,deep-learning,Validation,Machine Learning,Keras,Deep Learning,如果损失波动,最后的培训步骤可能没有最低的损失 我想知道,如果在Keras中训练模型得到验证,Keras如何选择最终模型 做 Keras通过从整个培训过程中选择验证数据损失最小的模型进行选择? 或 Keras从最终培训步骤中选择最终模型,不管最终模型是否给出了验证数据的最小损失? 谢谢。是的,默认情况下,Keras从最终培训步骤返回最终模型,无论最终模型是否提供了最小的验证数据损失 save_best_model = ModelCheckpoint(best_model_path, monito

如果损失波动,最后的培训步骤可能没有最低的损失

我想知道,如果在Keras中训练模型得到验证,Keras如何选择最终模型

Keras通过从整个培训过程中选择验证数据损失最小的模型进行选择? 或

Keras从最终培训步骤中选择最终模型,不管最终模型是否给出了验证数据的最小损失?
谢谢。

是的,默认情况下,Keras从最终培训步骤返回最终模型,无论最终模型是否提供了最小的验证数据损失

save_best_model = ModelCheckpoint(best_model_path, monitor='val_loss', 
                                  save_best_only=True, save_weights_only=True)

# fit model
model.fit(X_train, y_train, 
              batch_size=64,
              epochs=35,
              validation_data=(X_val, y_val), 
              callbacks=[save_best_model])

# select the best model
model.load_weights(best_model_path)
如果要使用验证数据损失最小的模型,则需要使用参数save_best_only的回调。完成培训后,需要加载保存的模型。就验证数据的损失而言,这将是最好的模型

save_best_model = ModelCheckpoint(best_model_path, monitor='val_loss', 
                                  save_best_only=True, save_weights_only=True)

# fit model
model.fit(X_train, y_train, 
              batch_size=64,
              epochs=35,
              validation_data=(X_val, y_val), 
              callbacks=[save_best_model])

# select the best model
model.load_weights(best_model_path)