-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
48 lines (43 loc) · 1.28 KB
/
models.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
import torch.nn as nn
import torch.nn.functional as F
class MLP(nn.Module):
def __init__(self):
super(MLP, self).__init__()
self.fc1 = nn.Linear(64, 40)
self.fc2 = nn.Linear(40, 20)
self.fc3 = nn.Linear(20, 10)
def forward(self, x):
out = F.relu(self.fc1(x))
out = F.relu(self.fc2(out))
out = self.fc3(out)
return out
class MLP_R(nn.Module):
def __init__(self):
super(MLP_R, self).__init__()
self.fc1 = nn.Linear(1, 10)
self.fc2 = nn.Linear(10, 1)
def forward(self,x):
out = F.elu(self.fc1(x))
out = self.fc2(out)
return out
class CNN(nn.Module):
def __init__(self):
super(CNN, self).__init__()
self.conv1 = nn.Conv2d(1, 4, 5)
self.relu1 = nn.RReLU()
self.pool1 = nn.MaxPool2d(2)
self.conv2 = nn.Conv2d(4, 8, 5)
self.relu2 = nn.RReLU()
self.pool2 = nn.MaxPool2d(2)
self.fc1 = nn.Linear(128, 10)
def forward(self, x):
out = self.conv1(x)
out = self.relu1(out)
out = self.pool1(out)
out = self.conv2(out)
out = self.relu2(out)
out = self.pool2(out)
out = out.view(out.shape[0], -1)
out = self.fc1(out)
return out