-
Notifications
You must be signed in to change notification settings - Fork 0
/
nets.py
74 lines (62 loc) · 2.77 KB
/
nets.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
import torch.nn as nn
import sys
class DOLL(nn.Module):
def __init__(self, style_dim=9216):
super(DOLL, self).__init__()
self.decomposer = nn.Sequential(nn.Linear(style_dim, style_dim),
nn.ReLU(),
nn.Linear(style_dim, style_dim),
nn.ReLU(),
nn.Linear(style_dim, style_dim))
self.transformer = nn.Sequential(nn.Linear(style_dim, style_dim),
nn.ReLU(),
nn.Linear(style_dim, style_dim),
nn.ReLU(),
nn.Linear(style_dim, style_dim))
def forward(self, latent):
z_related = self.decomposer(latent)
z_unrelated = latent - z_related
z_related_transform = self.transformer(z_related)
return latent, z_unrelated, z_related, z_related_transform
class DOLLResidual(nn.Module):
def __init__(self, style_dim=9216):
super(DOLLResidual, self).__init__()
self.decomposer = nn.Sequential(nn.Linear(style_dim, style_dim),
nn.ReLU(),
nn.Linear(style_dim, style_dim),
nn.ReLU(),
nn.Linear(style_dim, style_dim))
self.transformer = nn.Sequential(nn.Linear(style_dim, style_dim),
nn.ReLU(),
nn.Linear(style_dim, style_dim),
nn.ReLU(),
nn.Linear(style_dim, style_dim))
def forward(self, latent):
z_related = self.decomposer(latent)
z_unrelated = latent - z_related
z_delta = self.transformer(z_related)
return latent, z_unrelated, z_related, z_delta
class LCNet(nn.Module):
def __init__(self, fmaps=[9216, 2048, 512, 40], activ='relu'):
super().__init__()
# Linear layers
self.fcs = nn.ModuleList()
for i in range(len(fmaps) - 1):
in_channel = fmaps[i]
out_channel = fmaps[i + 1]
self.fcs.append(nn.Linear(in_channel, out_channel, bias=True),
# nn.Dropout(0.5),
)
print('new!')
# Activation
if activ == 'relu':
self.activ = nn.ReLU()
elif activ == 'leakyrelu':
self.activ = nn.LeakyReLU(0.2)
else:
raise NotImplementedError
def forward(self, x):
for layer in self.fcs[:-1]:
x = self.activ(layer(x))
x = self.fcs[-1](x)
return x