summaryrefslogtreecommitdiff
path: root/text_recognizer
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2022-06-02 23:38:19 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2022-06-02 23:38:19 +0200
commit1f3ab1c091b44b119765f785eab16e7dd06dfa4d (patch)
treed24f31738b8968a28f29328bc0ef98497c50fac8 /text_recognizer
parent90f7e3882610945077949b96a011c92a8e7c8106 (diff)
Add mlp conformer layer
Diffstat (limited to 'text_recognizer')
-rw-r--r--text_recognizer/networks/conformer/mlp.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/text_recognizer/networks/conformer/mlp.py b/text_recognizer/networks/conformer/mlp.py
index e69de29..031bde9 100644
--- a/text_recognizer/networks/conformer/mlp.py
+++ b/text_recognizer/networks/conformer/mlp.py
@@ -0,0 +1,17 @@
+"""Conformer feedforward block."""
+from torch import nn, Tensor
+
+
+class MLP(nn.Module):
+ def __init__(self, dim: int, mult: int = 4, dropout: float = 0.0) -> None:
+ super().__init__()
+ self.layers = nn.Sequential(
+ nn.Linear(dim, mult * dim),
+ nn.Mish(inplace=True),
+ nn.Dropout(dropout),
+ nn.Linear(mult * dim, dim),
+ nn.Dropout(dropout),
+ )
+
+ def forward(self, x: Tensor) -> Tensor:
+ return self.layers(x)