-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
45 lines (40 loc) · 1.33 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import torch
import torch.nn as nn
class Model(nn.Module):
def __init__(self, num_classes=36, num_chars=4):
super(Model, self).__init__()
# image size = 90 * 25
# batch * 1 * 90 * 25
self.conv = nn.Sequential(
nn.Conv2d(1, 32, 3, padding=(1, 1)), # batch * 32 * 90 * 25
nn.BatchNorm2d(32),
nn.ReLU(),
nn.Dropout2d(0.25),
nn.Conv2d(32, 128, 3, padding=(1, 1)), # batch * 128 * 90 * 25
nn.MaxPool2d(2, 2), # batch * 128 * 45 * 12
nn.BatchNorm2d(128),
nn.ReLU(),
nn.Dropout2d(0.25),
nn.Conv2d(128, 256, 3, padding=(1, 1)), # batch * 256 * 45 * 12
nn.BatchNorm2d(256),
nn.ReLU(),
nn.Dropout2d(0.5),
nn.Conv2d(256, 256, 3, padding=(1, 1)),
nn.MaxPool2d(2, 2), # batch * 256 * 22 * 6
nn.BatchNorm2d(256),
nn.Dropout2d(0.25),
nn.ReLU(),
)
self.fc = nn.Linear(256 * 22 * 6, num_classes * num_chars)
def forward(self, x):
x = self.conv(x)
x = x.view(-1, 256 * 22 * 6)
x = self.fc(x)
return x
if __name__ == '__main__':
BATCH_SIZE = 4
x = torch.randn(BATCH_SIZE, 1, 90, 25)
print(x)
#model = Model()
#out = model(x)
#print(out)