-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathmnist_net.py
More file actions
35 lines (29 loc) · 856 Bytes
/
mnist_net.py
File metadata and controls
35 lines (29 loc) · 856 Bytes
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
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch
import torch.nn as nn
import torch.nn.functional as F
class MNISTNet(nn.Module):
def __init__(self):
super(MNISTNet, self).__init__()
self.conv1 = nn.Conv2d(...)
self.conv2 = nn.Conv2d(...)
self.pool = nn.MaxPool2d(...)
self.fc1 = nn.Linear(...)
self.fc2 = nn.Linear(...)
self.fc3 = nn.Linear(...)
def forward(self, x):
x = F.relu(self.conv1(x)) # First convolution followed by
x = self.pool(x) # a relu activation and a max pooling#
x = ...
...
x = self.fc3(x)
return x
def get_features(self, x):
pass
if __name__=='__main__':
x = torch.rand(16,1,28,28)
net = MNISTNet()
y = net(x)
assert y.shape == (16,10)