I'm currently fine-tuning a network for a few epochs using the following code:
es= keras.callbacks.EarlyStopping(monitor='loss', min_delta=1e-4,patience=10, verbose=True, restore_best_weights=True)
history = model.fit(ft, steps_per_epoch=len(ft), callbacks=[es], epochs=150, verbose=verbose)
model.save('model_best.h5')
I understand that if there is no improvement in the loss (monitored by monitor='loss'
) for 10 epochs (determined by patience=10
), the EarlyStopping callback is activated, and the model weights restored to the best encountered weights are saved.
My question is about the scenario where EarlyStopping does not trigger—say, if there isn't a sequence of 10 epochs without improvement, but the best performing epoch is not the last one. In this case, which weights are saved? Are they the weights from the last epoch or from the best epoch observed during training? Notably, when verbose=True
, the EarlyStopping callback does not produce any output if it doesn't trigger, leaving me unsure about which model version is preserved. Can someone clarify what happens in this situation?
By default, the model does not automatically save the weights of the best-
performing epoch
. You need to explicitly configure this behavior using a
callback like modelcheckpoint in libraries like keras or TensorFlow.
I am attaching gist file for your reference