-
Notifications
You must be signed in to change notification settings - Fork 10
/
model.py
81 lines (66 loc) · 2.31 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
import torch
from torch import nn
class FaceEncoder(nn.Module):
def __init__(self):
super(FaceEncoder, self).__init__()
self.encoder = nn.Sequential(
nn.Linear(96, 128),
nn.BatchNorm1d(128),
nn.ReLU(),
nn.Linear(128, 64),
nn.BatchNorm1d(64),
nn.ReLU(),
nn.Linear(64, 16),
)
for m in self.modules():
if isinstance(m, torch.nn.Linear):
torch.nn.init.kaiming_uniform_(m.weight, mode='fan_in', nonlinearity='relu')
elif isinstance(m, nn.BatchNorm1d):
m.weight.data.fill_(1)
m.bias.data.zero_()
def forward(self, x):
return self.encoder(x)
class AudioEncoder(nn.Module):
def __init__(self):
super(AudioEncoder, self).__init__()
self.encoder = nn.Sequential(
nn.Linear(12, 32),
nn.BatchNorm1d(32),
nn.ReLU(),
nn.Linear(32, 64),
nn.BatchNorm1d(64),
nn.ReLU(),
nn.Linear(64, 128),
)
for m in self.modules():
if isinstance(m, torch.nn.Linear):
torch.nn.init.kaiming_uniform_(m.weight, mode='fan_in', nonlinearity='relu')
elif isinstance(m, nn.BatchNorm1d):
m.weight.data.fill_(1)
m.bias.data.zero_()
def forward(self, x):
return self.encoder(x)
class FaceDecoder(nn.Module):
def __init__(self):
super(FaceDecoder, self).__init__()
h_GRU = 144
self.stabilizer = nn.GRU(144, h_GRU, 2, batch_first = True, dropout = 0.2)
self.decoder = nn.Sequential(
nn.Linear(144, 256),
nn.BatchNorm1d(256),
nn.ReLU(),
nn.Linear(256, 128),
nn.BatchNorm1d(128),
nn.ReLU(),
nn.Linear(128, 40),
nn.Sigmoid(),
)
for m in self.modules():
if isinstance(m, torch.nn.Linear):
torch.nn.init.kaiming_uniform_(m.weight, mode='fan_in', nonlinearity='relu')
elif isinstance(m, nn.BatchNorm1d):
m.weight.data.fill_(1)
m.bias.data.zero_()
def forward(self, x):
x, _ = self.stabilizer(x)
return self.decoder(x.reshape(-1, 144))