Skip to content
Discussion options

You must be logged in to vote

Hi,

look at ModelCheckpoint callback. After the training, you can use its attribute best_model_path to restore the best model.

Here is a simple code with EarlyStopping and ModelCheckpoint together (training is stopped when val_loss doesn't improve anymore).

# preparing my dataset
dm = MyDataModule()
dm.prepare_data()
dm.setup()

# initialize checkpoints
early_stop = EarlyStopping(monitor="val_loss", patience=10, mode="min")
checkpoint_callback = ModelCheckpoint(save_top_k=1, monitor="val_loss", mode="min")

# initialize the trainer
trainer = pl.Trainer(
    callbacks=[early_stop, checkpoint_callback],   # we use both checkpoints
    max_epochs=100,
    gpus=[0],
    enable_checkpointing=True

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by PascalIversen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment