From fd5836be8a47f04cd1a1ec4fd3d760a6577423d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Zalewski?= Date: Mon, 8 Nov 2021 21:15:54 +0100 Subject: [PATCH] Release/1.2 (#199) *add manual resetting of metrics at the end of every epoch *set `pytorch-lightning>=1.5` in `requirements.txt` --- configs/trainer/default.yaml | 2 ++ requirements.txt | 2 +- src/models/mnist_model.py | 11 +++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/configs/trainer/default.yaml b/configs/trainer/default.yaml index b2cc44e..53f9e2a 100644 --- a/configs/trainer/default.yaml +++ b/configs/trainer/default.yaml @@ -8,4 +8,6 @@ max_epochs: 10 progress_bar_refresh_rate: 5 resume_from_checkpoint: null weights_summary: "full" + +# number of validation steps to execute at the beginning of the training num_sanity_val_steps: 0 diff --git a/requirements.txt b/requirements.txt index 6376ee5..5d799f7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ # --------- pytorch --------- # torch>=1.10.0 torchvision>=0.11.0 -pytorch-lightning>=1.4.0 +pytorch-lightning>=1.5.0 torchmetrics>=0.6.0 # --------- hydra --------- # diff --git a/src/models/mnist_model.py b/src/models/mnist_model.py index 65fc091..6100315 100644 --- a/src/models/mnist_model.py +++ b/src/models/mnist_model.py @@ -50,7 +50,7 @@ class MNISTLitModel(LightningModule): self.val_acc = Accuracy() self.test_acc = Accuracy() - # for logging best accuracy achieved so far + # for logging best so far validation accuracy self.val_acc_best = MaxMetric() def forward(self, x: torch.Tensor): @@ -92,9 +92,6 @@ class MNISTLitModel(LightningModule): def validation_epoch_end(self, outputs: List[Any]): acc = self.val_acc.compute() # get val accuracy from current epoch - self.val_acc.reset() # reset is necessary if you're using `num_sanity_val_steps` in trainer - - # compute and log best so far val accuracy self.val_acc_best.update(acc) self.log("val/acc_best", self.val_acc_best.compute(), on_epoch=True, prog_bar=True) @@ -111,6 +108,12 @@ class MNISTLitModel(LightningModule): def test_epoch_end(self, outputs: List[Any]): pass + def on_epoch_end(self): + # reset metrics at the end of every epoch! + self.train_acc.reset() + self.test_acc.reset() + self.val_acc.reset() + def configure_optimizers(self): """Choose what optimizers and learning-rate schedulers to use in your optimization. Normally you'd need one. But in the case of GANs or similar you might have multiple.