Setting up early stopping and auto checkpoint on Keras

Talles L - Aug 19 - - Dev Community
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]
)
Enter fullscreen mode Exit fullscreen mode

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.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player