-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.py
89 lines (68 loc) · 2.16 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
import torch.nn as nn
import torch.nn.functional as F
class GeneratorX(nn.Module):
def __init__(self, zd=128, ch=1):
super().__init__()
self.net = nn.Sequential(
nn.ConvTranspose2d(zd, zd, 4, 1),
nn.BatchNorm2d(zd),
nn.LeakyReLU(0.02),
nn.ConvTranspose2d(zd, zd//2, 5, 2),
nn.BatchNorm2d(zd//2),
nn.LeakyReLU(0.02),
nn.ConvTranspose2d(zd//2, zd//4, 5, 2),
nn.BatchNorm2d(zd//4),
nn.LeakyReLU(0.02),
nn.ConvTranspose2d(zd//4, ch, 4, 1),
nn.Sigmoid()
)
def forward(self, x):
return self.net(x)
class GeneratorZ(nn.Module):
def __init__(self, zd=128, ch=1):
super().__init__()
self.net = nn.Sequential(
nn.Conv2d(ch, zd//4, 5, 1),
nn.BatchNorm2d(zd//4),
nn.LeakyReLU(0.02),
nn.Conv2d(zd//4, zd//2, 5, 2),
nn.BatchNorm2d(zd//2),
nn.LeakyReLU(0.02),
nn.Conv2d(zd//2, zd, 3, 2),
nn.BatchNorm2d(zd),
nn.LeakyReLU(0.02),
nn.Conv2d(zd, zd*2, 4, 1),
nn.BatchNorm2d(zd*2),
nn.LeakyReLU(0.02),
nn.Conv2d(zd*2, zd*2, 1, 1),
)
def forward(self, x):
return self.net(x)
class DiscriminatorX(nn.Module):
def __init__(self, zd=128):
super().__init__()
self.net = nn.Sequential(
nn.Conv2d(1, zd//4, 5, 1),
nn.LeakyReLU(0.02),
nn.Conv2d(zd//4, zd//2, 5, 2),
nn.LeakyReLU(0.02),
nn.Conv2d(zd//2, zd, 3, 2),
nn.LeakyReLU(0.02),
nn.Conv2d(zd, zd, 4, 1),
nn.LeakyReLU(0.02)
)
def forward(self, x):
return self.net(x)
class DiscriminatorXZ(nn.Module):
def __init__(self, zd=128):
super().__init__()
self.net = nn.Sequential(
nn.Conv2d(zd*2, zd*2, 1, 1),
nn.LeakyReLU(0.02),
nn.Conv2d(zd*2, zd, 1, 1),
nn.LeakyReLU(0.02),
nn.Conv2d(zd, 1, 1, 1),
)
def forward(self, x):
return self.net(x)