I am using Keras' EarlyStopping callback function, saving only the best weights and setting a patience of say 10 epochs. I am wondering whether the predict function is using the weights of the last epoch of training or the ones of the best epoch. A minimal example would be:
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)
Thank you in advance for your help!
CodePudding user response:
Because you're using restore_best_weights=True
, yes, the model is set to its best weights after training.
If that was not True
, you'd have to save the weights during training with a ModelCheckpoint
callback and later load the saved weights.