-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmodel.py
61 lines (44 loc) · 2.01 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import torch
torch.manual_seed(123)
from torch.nn import Module, Conv2d, MaxPool2d, Linear, Dropout, BatchNorm2d
import torch.nn.functional as F
class genreNet(Module):
def __init__(self):
super(genreNet, self).__init__()
self.conv1 = Conv2d(in_channels=1, out_channels=64, kernel_size=3, stride=1, padding=1)
torch.nn.init.xavier_uniform(self.conv1.weight)
self.bn1 = BatchNorm2d(64)
self.pool1 = MaxPool2d(kernel_size=2)
self.conv2 = Conv2d(in_channels=64, out_channels=128, kernel_size=3, stride=1, padding=1)
torch.nn.init.xavier_uniform(self.conv2.weight)
self.bn2 = BatchNorm2d(128)
self.pool2 = MaxPool2d(kernel_size=2)
self.conv3 = Conv2d(in_channels=128, out_channels=256, kernel_size=3, stride=1, padding=1)
torch.nn.init.xavier_uniform(self.conv3.weight)
self.bn3 = BatchNorm2d(256)
self.pool3 = MaxPool2d(kernel_size=4)
self.conv4 = Conv2d(in_channels=256, out_channels=512, kernel_size=3, stride=1, padding=1)
torch.nn.init.xavier_uniform(self.conv4.weight)
self.bn4 = BatchNorm2d(512)
self.pool4 = MaxPool2d(kernel_size=4)
self.fc1 = Linear(in_features=2048, out_features=1024)
self.drop1 = Dropout(0.5)
self.fc2 = Linear(in_features=1024, out_features=256)
self.drop2 = Dropout(0.5)
self.fc3 = Linear(in_features=256, out_features=10)
def forward(self, inp):
x = F.relu(self.bn1(self.conv1(inp)))
x = self.pool1(x)
x = F.relu(self.bn2(self.conv2(x)))
x = self.pool2(x)
x = F.relu(self.bn3(self.conv3(x)))
x = self.pool3(x)
x = F.relu(self.bn4(self.conv4(x)))
x = self.pool4(x)
x = x.view(x.size()[0], -1)
x = F.relu(self.fc1(x))
x = self.drop1(x)
x = F.relu(self.fc2(x))
x = self.drop2(x)
x = F.log_softmax(self.fc3(x))
return x