Skip to content

Commit e2ee4dd

Browse files
Adrian WälchliwilliamFalcon
Adrian Wälchli
authored andcommitted
Fix early stopping off by 2 (min_epochs) (#617)
* fix early stopping off by 2 * add min_epochs example in docs
1 parent d562172 commit e2ee4dd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pytorch_lightning/trainer/training_loop.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
# pass in your own to override the default callback
5151
trainer = Trainer(early_stop_callback=early_stop_callback)
5252
53+
# pass in min_epochs to enable the callback after min_epochs have run
54+
trainer = Trainer(early_stop_callback=early_stop_callback, min_epochs=5)
55+
5356
# pass in None to disable it
5457
trainer = Trainer(early_stop_callback=None)
5558
@@ -339,7 +342,7 @@ def train(self):
339342
self.reduce_lr_on_plateau_scheduler.step(val_loss, epoch=self.current_epoch)
340343

341344
# early stopping
342-
met_min_epochs = epoch > self.min_epochs
345+
met_min_epochs = epoch >= self.min_epochs - 1
343346
if self.enable_early_stop and (met_min_epochs or self.fast_dev_run):
344347
should_stop = self.early_stop_callback.on_epoch_end(epoch=epoch,
345348
logs=self.callback_metrics)

0 commit comments

Comments
 (0)