From f8b8cc5b1a953744e7e0fed67d0764195eded9af Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Sun, 5 Jun 2022 21:21:14 +0200 Subject: Add conformer --- text_recognizer/networks/conformer/conformer.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 text_recognizer/networks/conformer/conformer.py diff --git a/text_recognizer/networks/conformer/conformer.py b/text_recognizer/networks/conformer/conformer.py new file mode 100644 index 0000000..d56955e --- /dev/null +++ b/text_recognizer/networks/conformer/conformer.py @@ -0,0 +1,17 @@ +"""Conformer module.""" +from copy import deepcopy + +from torch import nn, Tensor + +from text_recognizer.networks.conformer.block import ConformerBlock + + +class Conformer(nn.Module): + def __init__(self, block: ConformerBlock, depth: int) -> None: + super().__init__() + self.blocks = nn.ModuleList([deepcopy(block) for _ in range(depth)]) + + def forward(self, x: Tensor) -> Tensor: + for fn in self.blocks: + x = fn(x) + return x -- cgit v1.2.3-70-g09d2