summaryrefslogtreecommitdiff
path: root/text_recognizer/models
diff options
context:
space:
mode:
Diffstat (limited to 'text_recognizer/models')
-rw-r--r--text_recognizer/models/vqvae.py11
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)