From 91d0d49b9b0750f4b592d5fff6e440bb28f484dd Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Tue, 27 Sep 2022 00:11:13 +0200 Subject: Add logits @ token embeddings --- text_recognizer/networks/conv_transformer.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/text_recognizer/networks/conv_transformer.py b/text_recognizer/networks/conv_transformer.py index d2ab8ea..ddf3b2e 100644 --- a/text_recognizer/networks/conv_transformer.py +++ b/text_recognizer/networks/conv_transformer.py @@ -1,6 +1,7 @@ """Base network module.""" from typing import Optional, Tuple, Type +import torch from torch import Tensor, nn from text_recognizer.networks.transformer.decoder import Decoder @@ -108,6 +109,9 @@ class ConvTransformer(nn.Module): trg = self.token_embedding(trg) trg += self.token_pos_embedding(trg) out = self.decoder(x=trg, context=src, input_mask=trg_mask) + logits = ( + out @ torch.transpose(self.token_embedding.weight.to(trg.dtype), 0, 1) + ).float() logits = self.to_logits(out) # [B, Sy, C] logits = logits.permute(0, 2, 1) # [B, C, Sy] return logits -- cgit v1.2.3-70-g09d2