From 1bccf71cf4eec335001b50a8fbc0c991d0e6d13a Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Wed, 4 Aug 2021 22:15:36 +0200 Subject: Add conv attention, up and downsampling to vqvae module --- text_recognizer/networks/vqvae/norm.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 text_recognizer/networks/vqvae/norm.py (limited to 'text_recognizer/networks/vqvae/norm.py') diff --git a/text_recognizer/networks/vqvae/norm.py b/text_recognizer/networks/vqvae/norm.py new file mode 100644 index 0000000..df66efc --- /dev/null +++ b/text_recognizer/networks/vqvae/norm.py @@ -0,0 +1,20 @@ +"""Normalizer block.""" +import attr +from torch import nn, Tensor + + +@attr.s +class Normalize(nn.Module): + num_channels: int = attr.ib() + norm: nn.GroupNorm = attr.ib(init=False) + + def __attrs_post_init__(self) -> None: + """Post init configuration.""" + super().__init__() + self.norm = nn.GroupNorm( + num_groups=32, num_channels=self.num_channels, eps=1.0e-6, affine=True + ) + + def forward(self, x: Tensor) -> Tensor: + """Applies group normalization.""" + return self.norm(x) -- cgit v1.2.3-70-g09d2