-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_small.py
40 lines (34 loc) · 1.09 KB
/
model_small.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
import torch.nn as nn
class SmallCnn(nn.Module):
def __init__(self, n_classes):
super().__init__()
self.conv1 = nn.Sequential(
nn.Conv2d(in_channels=3, out_channels=8, kernel_size=3),
nn.ReLU(),
nn.MaxPool2d(kernel_size=3)
)
self.conv2 = nn.Sequential(
nn.Conv2d(in_channels=8, out_channels=16, kernel_size=3),
nn.ReLU(),
nn.MaxPool2d(kernel_size=3)
)
self.conv3 = nn.Sequential(
nn.Conv2d(in_channels=16, out_channels=32, kernel_size=3),
nn.ReLU(),
nn.MaxPool2d(kernel_size=3)
)
self.conv4 = nn.Sequential(
nn.Conv2d(in_channels=32, out_channels=32, kernel_size=3),
nn.ReLU(),
nn.MaxPool2d(kernel_size=3)
)
self.out = nn.Linear(32, n_classes)
def forward(self, x):
x = self.conv1(x)
x = self.conv2(x)
x = self.conv3(x)
x = self.conv4(x)
# print(x.shape)
x = x.view(x.size(0), -1)
logits = self.out(x)
return logits