Release/1.2 (#199)

*add manual resetting of metrics at the end of every epoch
*set `pytorch-lightning>=1.5` in `requirements.txt`
This commit is contained in:
Łukasz Zalewski authored and GitHub committed 2021-11-08 21:15:54 +01:00
1 parent 9468ef91c5
commit fd5836be8a
3 files changed
+10 -5

No files matched your search

+2
View File
@@ -8,4 +8,6 @@ max_epochs: 10
progress_bar_refresh_rate: 5 progress_bar_refresh_rate: 5
resume_from_checkpoint: null resume_from_checkpoint: null
weights_summary: "full" weights_summary: "full"
# number of validation steps to execute at the beginning of the training
num_sanity_val_steps: 0 num_sanity_val_steps: 0
+1 -1
View File
@@ -1,7 +1,7 @@
# --------- pytorch --------- # # --------- pytorch --------- #
torch>=1.10.0 torch>=1.10.0
torchvision>=0.11.0 torchvision>=0.11.0
pytorch-lightning>=1.4.0 pytorch-lightning>=1.5.0
torchmetrics>=0.6.0 torchmetrics>=0.6.0
# --------- hydra --------- # # --------- hydra --------- #
+7 -4
View File
@@ -50,7 +50,7 @@ class MNISTLitModel(LightningModule):
self.val_acc = Accuracy() self.val_acc = Accuracy()
self.test_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() self.val_acc_best = MaxMetric()
def forward(self, x: torch.Tensor): def forward(self, x: torch.Tensor):
@@ -92,9 +92,6 @@ class MNISTLitModel(LightningModule):
def validation_epoch_end(self, outputs: List[Any]): def validation_epoch_end(self, outputs: List[Any]):
acc = self.val_acc.compute() # get val accuracy from current epoch 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.val_acc_best.update(acc)
self.log("val/acc_best", self.val_acc_best.compute(), on_epoch=True, prog_bar=True) 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]): def test_epoch_end(self, outputs: List[Any]):
pass 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): def configure_optimizers(self):
"""Choose what optimizers and learning-rate schedulers to use in your optimization. """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. Normally you'd need one. But in the case of GANs or similar you might have multiple.