Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix early stopping off by 2 (min_epochs) #617

Merged
merged 2 commits into from
Dec 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pytorch_lightning/trainer/training_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
# pass in your own to override the default callback
trainer = Trainer(early_stop_callback=early_stop_callback)

# pass in min_epochs to enable the callback after min_epochs have run
trainer = Trainer(early_stop_callback=early_stop_callback, min_epochs=5)

# pass in None to disable it
trainer = Trainer(early_stop_callback=None)

Expand Down Expand Up @@ -339,7 +342,7 @@ def train(self):
self.reduce_lr_on_plateau_scheduler.step(val_loss, epoch=self.current_epoch)

# early stopping
met_min_epochs = epoch > self.min_epochs
met_min_epochs = epoch >= self.min_epochs - 1
if self.enable_early_stop and (met_min_epochs or self.fast_dev_run):
should_stop = self.early_stop_callback.on_epoch_end(epoch=epoch,
logs=self.callback_metrics)
Expand Down