[BUG] Early stopping does not seem to work

The early stopping callback does not work as expected, and crashes at the end of
max_epochs with:

```
~/miniconda3/envs/py38/lib/python3.8/site-packages/pytorch_lightning/trainer/callback_hook.py in on_train_end(self)
    155         """Called when the train ends."""
    156         for callback in self.callbacks:
--> 157             callback.on_train_end(self, self.lightning_module)
    158
    159     def on_pretrain_routine_start(self) -> None:

~/work/repos/prototorch_models/prototorch/models/callbacks.py in on_train_end(self, trainer, pl_module)
     18     def on_train_end(self, trainer, pl_module):
     19         # instead, do it at the end of training loop
---> 20         self._run_early_stopping_check(trainer, pl_module)
     21
     22

TypeError: _run_early_stopping_check() takes 2 positional arguments but 3 were given
```
This commit is contained in:
Jensun Ravichandran
2021-06-02 12:44:34 +02:00
parent bdacc83185
commit ef6bcc1079
3 changed files with 46 additions and 6 deletions

View File

@@ -46,19 +46,27 @@ if __name__ == "__main__":
vis = pt.models.VisGLVQ2D(train_ds)
pruning = pt.models.PruneLoserPrototypes(
threshold=0.01, # prune prototype if it wins less than 1%
prune_after_epochs=30, # pruning too early may cause problems
idle_epochs=30, # pruning too early may cause problems
prune_quota_per_epoch=1, # prune at most 1 prototype per epoch
frequency=5, # prune every fifth epoch
verbose=True,
)
es = pt.models.EarlyStopWithoutVal(
monitor="loss",
min_delta=0.1,
patience=3,
mode="min",
verbose=True,
)
# Setup trainer
trainer = pl.Trainer.from_argparse_args(
args,
max_epochs=100,
max_epochs=250,
callbacks=[
vis,
pruning,
es,
],
terminate_on_nan=True,
weights_summary=None,