-
Notifications
You must be signed in to change notification settings - Fork 1
/
models.py
36 lines (31 loc) · 1.25 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
import torch.nn as nn
class NN(nn.Module):
def __init__(self, input_dim, depth, width):
super(NN, self).__init__()
self.layers = nn.ModuleList()
self.layers.append(nn.Linear(input_dim,width))
self.layers.append(nn.ReLU())
for i in range(depth-1):
self.layers.append(nn.Linear(width, width))
self.layers.append(nn.ReLU())
self.layers.append(nn.Linear(width,1))
def forward(self, x):
for i in range(len(self.layers)):
x = self.layers[i](x)
return x
class CNN(nn.Module):
def __init__(self, input_dim, in_channels=1, depth=1, width=100):
super(CNN, self).__init__()
self.layers = nn.ModuleList()
self.layers.append( nn.Conv1d(in_channels, width, kernel_size=3, padding=1, stride=1))
self.layers.append(nn.ReLU(inplace=True))
for i in range(depth-1):
self.layers.append(nn.Conv1d(width, width, kernel_size=3, padding=1, stride=1))
self.layers.append(nn.ReLU(inplace=True))
self.fclast = nn.Linear(width * input_dim, 1)
def forward(self, x):
for i in range(len(self.layers)):
x = self.layers[i](x)
x = x.view(x.size(0), -1)
x = self.fclast(x)
return x