-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdefine_network.py
52 lines (42 loc) · 1.25 KB
/
define_network.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
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable
class AutoEncoder(nn.Module):
def __init__(self):
super(AutoEncoder, self).__init__()
self.encoder = nn.Sequential(
nn.Conv1d(1,5,4,stride=4),
nn.Tanh(),
nn.Conv1d(5,10,4,stride=4),
nn.Tanh(),
nn.Conv1d(10,5,3,stride=3),
nn.Tanh()
)
self.decoder = nn.Sequential(
nn.ConvTranspose1d(5,10,3,stride=3),
nn.Tanh(),
nn.ConvTranspose1d(10,5,4,stride=4),
nn.Tanh(),
nn.ConvTranspose1d(5,1,4,stride=4)
)
def forward(self, x):
x = self.encoder(x)
x = self.decoder(x)
return x
class Compression_encoder(nn.Module):
def __init__(self):
super(Compression_encoder, self).__init__()
self.encoder = nn.Sequential(
nn.Conv1d(1,5,4,stride=4),
nn.Tanh(),
nn.Conv1d(5,10,4,stride=4),
nn.Tanh(),
nn.Conv1d(10,5,3,stride=3),
nn.Tanh()
)
def forward(self, x):
x = self.encoder(x)
batchsize = x.size()[0]
x = x.resize(batchsize,5)
return x