-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneural_net.py
48 lines (37 loc) · 1.12 KB
/
neural_net.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
import torch
from torch import nn
class StupidNet(nn.Module):
def __init__(self, width, height):
super(StupidNet, self).__init__()
self.flatten = nn.Flatten()
self.linearStack = nn.Sequential(
nn.Linear(width * height, 128),
nn.ReLU(),
nn.Linear(128, 64),
nn.ReLU(),
nn.Linear(64, 10),
)
def forward(self, x):
x = self.flatten(x)
logits = self.linearStack(x)
return logits
class MidNet(nn.Module):
def __init__(self):
super(MidNet, self).__init__()
self.conv1 = nn.Sequential(
nn.Conv2d(
in_channels=1, out_channels=16, kernel_size=5, stride=1, padding=2
),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2),
)
self.conv2 = nn.Sequential(
nn.Conv2d(16, 32, 5, 1, 2), nn.ReLU(), nn.MaxPool2d(2)
)
self.out = nn.Linear(32 * 7 * 7, 10)
def forward(self, x):
x = self.conv1(x)
x = self.conv2(x)
x = x.view(x.size(0), -1)
output = self.out(x)
return output