-
Notifications
You must be signed in to change notification settings - Fork 18
/
Lenet.py
27 lines (25 loc) · 888 Bytes
/
Lenet.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
import torch.nn as nn
import torch.nn.functional as F
class Lenet(nn.Module):
def __init__(self):
super(Lenet, self).__init__()
self.conv1 = nn.Conv2d(1,6,5,stride=1,padding=2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(400, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
self.T_revision = nn.Linear(10, 10, False)
def forward(self, x, revision=True):
correction = self.T_revision.weight
out = F.relu(self.conv1(x))
out = F.max_pool2d(out, 2)
out = F.relu(self.conv2(out))
out = F.max_pool2d(out, 2)
out = out.view(out.size(0), -1)
out = F.relu(self.fc1(out))
out = F.relu(self.fc2(out))
out = self.fc3(out)
if revision == True:
return out, correction
else:
return out