Setting up early stopping and auto checkpoint on Keras
Talles L

Talles L @tallesl

About: nothing to see here, move along

Location:
Brazil
Joined:
Jul 12, 2020

Setting up early stopping and auto checkpoint on Keras

Publish Date: Aug 19 '24
0 0
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.

Comments 0 total

    Add comment