-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAutoEncoder.py
More file actions
executable file
·51 lines (34 loc) · 1.16 KB
/
AutoEncoder.py
File metadata and controls
executable file
·51 lines (34 loc) · 1.16 KB
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
from torch import nn
import torch
class Encoder(nn.Module):
def __init__(self, input_size, latent_size=10, ngpu=0):
super(Encoder, self).__init__()
self.ngpu = ngpu
# 定义Encoder
self.__Encoder = nn.Sequential(
nn.Linear(input_size,input_size//2),
nn.ReLU(inplace=True),
nn.Linear(input_size//2, input_size//4),
nn.ReLU(inplace=True),
nn.Linear(input_size//4, latent_size),
nn.ReLU(inplace=True)
)
def forward(self, x):
encoder = self.__Encoder(x)
return encoder
class Decoder(nn.Module):
def __init__(self, input_size, latent_size=10, ngpu=0):
super(Decoder, self).__init__()
self.ngpu = ngpu
# 定义Decoder
self.__Decoder = nn.Sequential(
nn.Linear(latent_size, input_size // 4),
nn.ReLU(inplace=True),
nn.Linear(input_size // 4, input_size // 2),
nn.ReLU(inplace=True),
nn.Linear(input_size // 2, input_size),
nn.Sigmoid()
)
def forward(self,x):
decoder = self.__Decoder(x)
return decoder