model.predict() 是否使用了模型的最佳权重?

Does model.predict() use use the best weights of the model?

我正在使用 Keras 的 EarlyStopping 回调函数,仅保存最佳权重并设置耐心,例如 10 个纪元。我想知道预测函数是使用最后一个训练时期的权重还是最佳时期的权重。一个最小的例子是:

callback = tensorflow.keras.callbacks.EarlyStopping(monitor="val_loss", patience = 10, min_delta=0.0003, restore_best_weights=True)

history = model.fit(x_train_noisy, x_train, validation_data=(x_test_noisy, x_test), epochs= 100, batch_size=batch_size, callbacks = callback)
model.save("model.h5")
prediction = model.predict(x_test_noisy)

提前感谢您的帮助!

因为您使用的是 restore_best_weights=True,是的,模型在训练后设置为最佳权重。

如果不是 True,您必须在训练期间使用 ModelCheckpoint 回调保存权重,然后加载保存的权重。