-
Notifications
You must be signed in to change notification settings - Fork 11
/
model.py
57 lines (49 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
import torch
import torch.nn as nn
import torch.nn.functional as F
class Net_mnist(nn.Module):
def __init__(self):
super(Net_mnist, self).__init__()
self.conv1 = nn.Conv2d(1, 20, 5, 1)
self.conv2 = nn.Conv2d(20, 50, 5, 1)
self.fc1 = nn.Linear(4*4*50, 128)
self.fc2 = nn.Linear(128, 10)
def forward(self, x):
x = torch.tanh(self.conv1(x))
x = F.max_pool2d(x, 2, 2)
x = torch.tanh(self.conv2(x))
x = F.max_pool2d(x, 2, 2)
x = x.view(-1, 4*4*50)
x = torch.tanh(self.fc1(x))
x = self.fc2(x)
return x
class Net_cifar10(nn.Module):
def __init__(self):
super(Net_cifar10, self).__init__()
self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 128)
self.fc2 = nn.Linear(128, 10)
def forward(self, x):
x = self.pool(torch.tanh(self.conv1(x)))
x = self.pool(torch.tanh(self.conv2(x)))
x = x.view(-1, 16 * 5 * 5)
x = torch.tanh(self.fc1(x))
x = self.fc2(x)
return x
class Net_cifar100(nn.Module):
def __init__(self):
super(Net_cifar100, self).__init__()
self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 128)
self.fc2 = nn.Linear(128, 100)
def forward(self, x):
x = self.pool(torch.tanh(self.conv1(x)))
x = self.pool(torch.tanh(self.conv2(x)))
x = x.view(-1, 16 * 5 * 5)
x = torch.tanh(self.fc1(x))
x = self.fc2(x)
return x