-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
64 lines (55 loc) · 2.05 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import torch.nn as nn
import torch as torch
import matplotlib.pyplot as plt
import numpy as np
class Generator(nn.Module):
def __init__(self):
super().__init__()
self.seq = nn.Sequential(
nn.ConvTranspose2d(128, 1024,4,bias=False),
nn.BatchNorm2d(1024),
nn.LeakyReLU(negative_slope=0.2,inplace=True),
# 4x4x1024
nn.ConvTranspose2d(1024, 512,4,stride=2, bias=False, padding=1),
nn.BatchNorm2d(512),
nn.LeakyReLU(negative_slope=0.2,inplace=True),
# 8x8x512
nn.ConvTranspose2d(512, 256,4,stride=2, bias=False, padding=1),
nn.BatchNorm2d(256),
nn.LeakyReLU(negative_slope=0.2,inplace=True),
# 16x16x256
nn.ConvTranspose2d(256, 128,4,stride=2, bias=False, padding=1),
nn.BatchNorm2d(128),
nn.LeakyReLU(negative_slope=0.2,inplace=True),
# 32x32x128
nn.ConvTranspose2d(128, 3,4,stride=2, bias=False, padding=1),
# nn.BatchNorm2d(),
# nn.LeakyReLU(negative_slope=0.2,inplace=True),
nn.Tanh()
# 28x28x1
)
def forward(self, x):
y = torch.reshape(x, (-1,128,1,1))
y = self.seq(y)
return y
class Discriminator(nn.Module):
def __init__(self):
super().__init__()
self.seq = nn.Sequential(
nn.Conv2d(3,32,5,bias=False),
nn.LeakyReLU(negative_slope=0.2,inplace=True),
nn.Conv2d(32,64,5,stride=2,bias=False),
nn.BatchNorm2d(64),
nn.LeakyReLU(negative_slope=0.2,inplace=True),
nn.Conv2d(64,128,5,stride=2,bias=False),
nn.BatchNorm2d(128),
nn.LeakyReLU(negative_slope=0.2,inplace=True),
nn.Conv2d(128,256,5,stride=2,bias=False),
nn.LeakyReLU(negative_slope=0.2,inplace=True),
nn.Conv2d(256,1,4,bias=False),
nn.Sigmoid(),
nn.Flatten()
)
def forward(self, x):
y = self.seq(x)
return y