-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathmodels.py
44 lines (40 loc) · 1.33 KB
/
models.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
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 12 19:17:51 2019
@author: icetong
"""
import torch.nn as nn
class CNN(nn.Module):
def __init__(self, num_class=36, num_char=4):
super(CNN, self).__init__()
self.num_class = num_class
self.num_char = num_char
self.conv = nn.Sequential(
#batch*3*180*100
nn.Conv2d(3, 16, 3, padding=(1, 1)),
nn.MaxPool2d(2, 2),
nn.BatchNorm2d(16),
nn.ReLU(),
#batch*16*90*50
nn.Conv2d(16, 64, 3, padding=(1, 1)),
nn.MaxPool2d(2, 2),
nn.BatchNorm2d(64),
nn.ReLU(),
#batch*64*45*25
nn.Conv2d(64, 512, 3, padding=(1, 1)),
nn.MaxPool2d(2, 2),
nn.BatchNorm2d(512),
nn.ReLU(),
#batch*512*22*12
nn.Conv2d(512, 512, 3, padding=(1, 1)),
nn.MaxPool2d(2, 2),
nn.BatchNorm2d(512),
nn.ReLU(),
#batch*512*11*6
)
self.fc = nn.Linear(512*11*6, self.num_class*self.num_char)
def forward(self, x):
x = self.conv(x)
x = x.view(-1, 512*11*6)
x = self.fc(x)
return x