-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
41 lines (38 loc) · 1.42 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
import torch
import torchvision
from torch import nn
from torch.autograd import Variable
class autoencoder(nn.Module):
def __init__(self):
super(autoencoder, self).__init__()
self.encoder = nn.Sequential(
nn.Conv2d(3, 32, 3, stride=1, padding=1), # b, 16, 10, 10
nn.LeakyReLU(),
nn.Dropout(0.1),
nn.Conv2d(32, 64, 3, stride=1, padding=1), # b, 8, 3, 3
nn.LeakyReLU(),
nn.Dropout(0.1),
nn.Conv2d(64, 128, 3, stride=1, padding=1), # b, 8, 3, 3
nn.LeakyReLU(),
nn.Dropout(0.1),
nn.Conv2d(128, 256, 3, stride=1, padding=1), # b, 8, 3, 3
nn.LeakyReLU(),
nn.Dropout(0.1),
)
self.decoder = nn.Sequential(
nn.ConvTranspose2d(256, 128, 3, stride=1,padding = 1), # b, 16, 5, 5
nn.LeakyReLU(),
nn.Dropout(0.1),
nn.ConvTranspose2d(128, 64, 3, stride=1, padding=1), # b, 8, 15, 15
nn.LeakyReLU(),
nn.Dropout(0.1),
nn.ConvTranspose2d(64, 32, 3, stride=1, padding=1), # b, 8, 15, 15
nn.LeakyReLU(),
nn.Dropout(0.1),
nn.ConvTranspose2d(32, 3, 3, stride=1, padding=1), # b, 1, 28, 28
nn.Tanh()
)
def forward(self, x):
x = self.encoder(x)
x = self.decoder(x)
return x