summaryrefslogtreecommitdiff
path: root/text_recognizer/models/transformer.py
diff options
context:
space:
mode:
Diffstat (limited to 'text_recognizer/models/transformer.py')
-rw-r--r--text_recognizer/models/transformer.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/text_recognizer/models/transformer.py b/text_recognizer/models/transformer.py
index 75f7523..50bf73d 100644
--- a/text_recognizer/models/transformer.py
+++ b/text_recognizer/models/transformer.py
@@ -52,16 +52,16 @@ class TransformerLitModel(BaseLitModel):
data, targets = batch
# Compute the loss.
- logits = self.network(data, targets[:-1])
- loss = self.loss_fn(logits, targets[1:])
+ logits = self.network(data, targets[:, :-1])
+ loss = self.loss_fn(logits, targets[:, 1:])
self.log("val/loss", loss, prog_bar=True)
# Get the token prediction.
- pred = self(data)
- self.val_cer(pred, targets)
- self.log("val/cer", self.val_cer, on_step=False, on_epoch=True, prog_bar=True)
- self.test_acc(pred, targets)
- self.log("val/acc", self.test_acc, on_step=False, on_epoch=True)
+ # pred = self(data)
+ # self.val_cer(pred, targets)
+ # self.log("val/cer", self.val_cer, on_step=False, on_epoch=True, prog_bar=True)
+ # self.test_acc(pred, targets)
+ # self.log("val/acc", self.test_acc, on_step=False, on_epoch=True)
def test_step(self, batch: Tuple[Tensor, Tensor], batch_idx: int) -> None:
"""Test step."""
@@ -98,8 +98,8 @@ class TransformerLitModel(BaseLitModel):
for Sy in range(1, self.max_output_len):
context = output[:, :Sy] # (B, Sy)
- logits = self.network.decode(z, context) # (B, Sy, C)
- tokens = torch.argmax(logits, dim=-1) # (B, Sy)
+ logits = self.network.decode(z, context) # (B, C, Sy)
+ tokens = torch.argmax(logits, dim=1) # (B, Sy)
output[:, Sy : Sy + 1] = tokens[:, -1:]
# Early stopping of prediction loop if token is end or padding token.