-
Notifications
You must be signed in to change notification settings - Fork 40
/
net.py
53 lines (41 loc) · 1.46 KB
/
net.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
import sys
sys.path.append('../')
import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torch
from metalayers import *
Tensor = torch.cuda.FloatTensor if torch.cuda.is_available() else torch.FloatTensor
class Generator(nn.Module):
def __init__(self, params):
super().__init__()
self.noise_dim = params.noise_dims
self.gkernel = gkern1D(params.gkernlen, params.gkernsig)
self.FC = nn.Sequential(
nn.Linear(self.noise_dim, 256),
nn.LeakyReLU(0.2),
nn.Dropout(p=0.2),
nn.Linear(256, 32*16, bias=False),
nn.BatchNorm1d(32*16),
nn.LeakyReLU(0.2),
)
self.CONV = nn.Sequential(
ConvTranspose1d_meta(16, 16, 5, stride=2, bias=False),
nn.BatchNorm1d(16),
nn.LeakyReLU(0.2),
ConvTranspose1d_meta(16, 8, 5, stride=2, bias=False),
nn.BatchNorm1d(8),
nn.LeakyReLU(0.2),
ConvTranspose1d_meta(8, 4, 5, stride=2, bias=False),
nn.BatchNorm1d(4),
nn.LeakyReLU(0.2),
ConvTranspose1d_meta(4, 1, 5),
)
def forward(self, noise, params):
net = self.FC(noise)
net = net.view(-1, 16, 32)
net = self.CONV(net)
net = conv1d_meta(net + noise.unsqueeze(1), self.gkernel)
# net = conv1d_meta(net , self.gkernel)
net = torch.tanh(net* params.binary_amp) * 1.05
return net