diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-08-06 14:23:03 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2021-08-06 14:23:03 +0200 |
commit | d12f70402371dda586d457af2a3df7fb5b3130ad (patch) | |
tree | 0eac2cced6c03145218b3b5415d3cb4c58bf8c14 | |
parent | 263f2b7158d76bc0adad45309625910c0fa7b1fe (diff) |
Add logging of acc in VQVAE model
-rw-r--r-- | text_recognizer/models/vqvae.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/text_recognizer/models/vqvae.py b/text_recognizer/models/vqvae.py index 76b7ba6..ef9a59a 100644 --- a/text_recognizer/models/vqvae.py +++ b/text_recognizer/models/vqvae.py @@ -20,11 +20,16 @@ class VQVAELitModel(BaseLitModel): def training_step(self, batch: Tuple[Tensor, Tensor], batch_idx: int) -> Tensor: """Training step.""" data, _ = batch + reconstructions, vq_loss = self(data) loss = self.loss_fn(reconstructions, data) loss = loss + self.latent_loss_weight * vq_loss + self.log("train/vq_loss", vq_loss) self.log("train/loss", loss) + + self.train_acc(reconstructions, data) + self.log("train/acc", self.train_acc, on_step=False, on_epoch=True) return loss def validation_step(self, batch: Tuple[Tensor, Tensor], batch_idx: int) -> None: @@ -33,9 +38,13 @@ class VQVAELitModel(BaseLitModel): reconstructions, vq_loss = self(data) loss = self.loss_fn(reconstructions, data) loss = loss + self.latent_loss_weight * vq_loss + self.log("val/vq_loss", vq_loss) self.log("val/loss", loss, prog_bar=True) + self.val_acc(reconstructions, data) + self.log("val/acc", self.val_acc, on_step=False, on_epoch=True, prog_bar=True) + def test_step(self, batch: Tuple[Tensor, Tensor], batch_idx: int) -> None: """Test step.""" data, _ = batch @@ -44,3 +53,5 @@ class VQVAELitModel(BaseLitModel): loss = loss + self.latent_loss_weight * vq_loss self.log("test/vq_loss", vq_loss) self.log("test/loss", loss) + self.test_acc(reconstructions, data) + self.log("test/acc", self.test_acc, on_step=False, on_epoch=True) |