From d12f70402371dda586d457af2a3df7fb5b3130ad Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Fri, 6 Aug 2021 14:23:03 +0200 Subject: Add logging of acc in VQVAE model --- text_recognizer/models/vqvae.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'text_recognizer/models') 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) -- cgit v1.2.3-70-g09d2