-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
27 lines (24 loc) · 943 Bytes
/
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
import torch
class Model(torch.nn.Module):
def __init__(self):
super(Model, self).__init__()
self.conv_1 = torch.nn.Conv2d(in_channels=1, out_channels=32, kernel_size=3, stride=1, padding=1)
self.conv_2 = torch.nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3, stride=1, padding=1)
self.max_pool2d = torch.nn.MaxPool2d(kernel_size=2, stride=2)
self.linear_1 = torch.nn.Linear(7 * 7 * 64, 128)
self.linear_2 = torch.nn.Linear(128, 10)
self.dropout = torch.nn.Dropout(p=0.5)
self.relu = torch.nn.ReLU()
def forward(self, x):
x = self.conv_1(x)
x = self.relu(x)
x = self.max_pool2d(x)
x = self.conv_2(x)
x = self.relu(x)
x = self.max_pool2d(x)
x = x.reshape(x.size(0), -1)
x = self.linear_1(x)
x = self.relu(x)
x = self.dropout(x)
pred = self.linear_2(x)
return pred