-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
37 lines (30 loc) · 1.09 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
from torch import nn
import torch.nn.functional as F
class FashionMNISTConvnet(nn.Module):
def __init__(self):
super(FashionMNISTConvnet, self).__init__()
self.convlayer1 = nn.Sequential(
nn.Conv2d(in_channels=1, out_channels=32, kernel_size=3, padding=1),
nn.BatchNorm2d(32),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2),
)
self.convlayer2 = nn.Sequential(
nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3),
nn.BatchNorm2d(64),
nn.ReLU(),
nn.MaxPool2d(2),
)
self.fc1 = nn.Linear(in_features=64 * 6 * 6, out_features=600)
self.drop = nn.Dropout2d(0.25)
self.fc2 = nn.Linear(in_features=600, out_features=120)
self.fc3 = nn.Linear(in_features=120, out_features=10)
def forward(self, x):
x = self.convlayer1(x)
x = self.convlayer2(x)
x = x.view(-1, 64 * 6 * 6)
x = self.fc1(x)
x = self.drop(x)
x = self.fc2(x)
x = self.fc3(x)
return F.log_softmax(input=x, dim=1)