English CRNN v2 architecture
Browse files
english/shobdo_english.py
CHANGED
|
@@ -4,7 +4,7 @@ import torch.nn.functional as F
|
|
| 4 |
class ConvBnRelu(nn.Module):
|
| 5 |
def __init__(self, i, o, k=3, s=1, p=1):
|
| 6 |
super().__init__()
|
| 7 |
-
self.b = nn.Sequential(nn.Conv2d(i,o,k,s,p,bias=False),nn.BatchNorm2d(o),nn.ReLU(
|
| 8 |
def forward(self, x): return self.b(x)
|
| 9 |
|
| 10 |
class LightCNN(nn.Module):
|
|
@@ -25,11 +25,10 @@ class BiLSTMBlock(nn.Module):
|
|
| 25 |
super().__init__()
|
| 26 |
self.rnn=nn.LSTM(i,h,bidirectional=True,batch_first=True)
|
| 27 |
self.fc=nn.Linear(h*2,o)
|
| 28 |
-
def forward(self, x):
|
| 29 |
-
o,_=self.rnn(x); return self.fc(o)
|
| 30 |
|
| 31 |
class Model(nn.Module):
|
| 32 |
-
def __init__(self, input_channel=1, output_channel=256, hidden_size=256, num_class=
|
| 33 |
super().__init__()
|
| 34 |
self.cnn=LightCNN()
|
| 35 |
self.rnn=nn.Sequential(BiLSTMBlock(256,hidden_size,hidden_size),
|
|
@@ -37,4 +36,4 @@ class Model(nn.Module):
|
|
| 37 |
def forward(self, x):
|
| 38 |
f=self.cnn(x).permute(0,2,1)
|
| 39 |
o=self.rnn(f).permute(1,0,2)
|
| 40 |
-
return F.log_softmax(o,dim=2)
|
|
|
|
| 4 |
class ConvBnRelu(nn.Module):
|
| 5 |
def __init__(self, i, o, k=3, s=1, p=1):
|
| 6 |
super().__init__()
|
| 7 |
+
self.b = nn.Sequential(nn.Conv2d(i,o,k,s,p,bias=False),nn.BatchNorm2d(o),nn.ReLU(True))
|
| 8 |
def forward(self, x): return self.b(x)
|
| 9 |
|
| 10 |
class LightCNN(nn.Module):
|
|
|
|
| 25 |
super().__init__()
|
| 26 |
self.rnn=nn.LSTM(i,h,bidirectional=True,batch_first=True)
|
| 27 |
self.fc=nn.Linear(h*2,o)
|
| 28 |
+
def forward(self, x): o,_=self.rnn(x); return self.fc(o)
|
|
|
|
| 29 |
|
| 30 |
class Model(nn.Module):
|
| 31 |
+
def __init__(self, input_channel=1, output_channel=256, hidden_size=256, num_class=76):
|
| 32 |
super().__init__()
|
| 33 |
self.cnn=LightCNN()
|
| 34 |
self.rnn=nn.Sequential(BiLSTMBlock(256,hidden_size,hidden_size),
|
|
|
|
| 36 |
def forward(self, x):
|
| 37 |
f=self.cnn(x).permute(0,2,1)
|
| 38 |
o=self.rnn(f).permute(1,0,2)
|
| 39 |
+
return F.log_softmax(o,dim=2)
|