-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
71 lines (60 loc) · 1.66 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
* Title: On the relationship between predictive coding and backpropagation source code
* Author: Robert Rosenbaum
* Date: 2021
* Code version: 1.0
* Availability: https://github.com/RobertRosenbaum/PredictiveCodingVsBackProp
"""
import torch.nn as nn
def build_original_model():
model = nn.Sequential(
nn.Sequential(nn.Conv2d(1, 10, 3),
nn.ReLU(),
nn.MaxPool2d(2)
),
nn.Sequential(
nn.Conv2d(10, 5, 3),
nn.ReLU(),
nn.Flatten()
),
nn.Sequential(
nn.Linear(5 * 11 * 11, 50),
nn.ReLU()
),
nn.Sequential(
nn.Linear(50, 30),
nn.ReLU()
),
nn.Sequential(
nn.Linear(30, 10)
)
)
return model
def build_modified_model():
model = nn.Sequential(
# Layer 0 (Input): 28 x 28
nn.Sequential(
nn.Conv2d(in_channels=1, out_channels=5, kernel_size=3),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2)
),
# Layer 1: (5x) 13 x 13
nn.Sequential(
nn.Conv2d(in_channels=5, out_channels=10, kernel_size=2),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2),
nn.Flatten()
),
# Layer 2: (10x) 6 x 6
nn.Sequential(
nn.Linear(in_features=10 * 6 * 6, out_features=60),
nn.BatchNorm1d(60),
nn.ReLU()
),
# Layer 3: Linear 60
nn.Sequential(
nn.Linear(in_features=60, out_features=10)
)
# Layer 4 (Output): Linear 10
)
return model