diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2022-09-27 00:11:13 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2022-09-27 00:11:13 +0200 |
commit | 91d0d49b9b0750f4b592d5fff6e440bb28f484dd (patch) | |
tree | 35dd8d67e305ba6fbfdfb41284edb451d35b0a8b | |
parent | 862182eaf4e0cc88e26e53609c67d9b98451f14c (diff) |
Add logits @ token embeddings
-rw-r--r-- | text_recognizer/networks/conv_transformer.py | 4 |
1 files changed, 4 insertions, 0 deletions
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 |