diff options
Diffstat (limited to 'text_recognizer/networks/vqvae/resize.py')
-rw-r--r-- | text_recognizer/networks/vqvae/resize.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/text_recognizer/networks/vqvae/resize.py b/text_recognizer/networks/vqvae/resize.py new file mode 100644 index 0000000..769d089 --- /dev/null +++ b/text_recognizer/networks/vqvae/resize.py @@ -0,0 +1,19 @@ +"""Up and down-sample with linear interpolation.""" +from torch import nn, Tensor +import torch.nn.functional as F + + +class Upsample(nn.Module): + """Upsamples by a factor 2.""" + + def forward(self, x: Tensor) -> Tensor: + """Applies upsampling.""" + return F.interpolate(x, scale_factor=2, mode="nearest") + + +class Downsample(nn.Module): + """Downsampling by a factor 2.""" + + def forward(self, x: Tensor) -> Tensor: + """Applies downsampling.""" + return F.avg_pool2d(x, kernel_size=2, stride=2) |