Setting up early stopping and auto checkpoint on Keras



This content originally appeared on DEV Community and was authored by Talles L

model_checkpoint = keras.callbacks.ModelCheckpoint('my_model.keras', save_best_only=true)
early_stopping = keras.callbacks.EarlyStopping(patience=5, restore_best_weights=True)

model.fit(
    ...,
    callbacks=[model_checkpoint, early_stopping]
)

ModelCheckpoint will save the model weights at the end of every epoch trained (only if the loss improved when enabling save_best_only).

EarlyStopping will stop the training earlier (than the configured epochs) as soon it stops yield better losses (it will try patience times until gives up).

See keras.callbacks.ModelCheckpoint and keras.callbacks.EarlyStopping for more.


This content originally appeared on DEV Community and was authored by Talles L