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.
Top comments (0)