-
Notifications
You must be signed in to change notification settings - Fork 11
/
modules.py
59 lines (47 loc) · 1.83 KB
/
modules.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
import torch
def conv2d_bn_leakrelu(inch, outch, kernel_size, stride=1, padding=1):
convlayer = torch.nn.Sequential(
torch.nn.Conv2d(inch, outch, kernel_size=kernel_size,
stride=stride, padding=padding),
torch.nn.BatchNorm2d(outch),
torch.nn.LeakyReLU()
)
return convlayer
def conv2d_bn_relu(inch, outch, kernel_size, stride=1, padding=1):
convlayer = torch.nn.Sequential(
torch.nn.Conv2d(inch, outch, kernel_size=kernel_size,
stride=stride, padding=padding),
torch.nn.BatchNorm2d(outch),
torch.nn.ReLU()
)
return convlayer
def deconv_tanh(inch, outch, kernel_size, stride=1, padding=1):
convlayer = torch.nn.Sequential(
torch.nn.ConvTranspose2d(
inch, outch, kernel_size=kernel_size, stride=stride, padding=padding),
torch.nn.Tanh()
)
return convlayer
def deconv_sigmoid(inch, outch, kernel_size, stride=1, padding=1, sigmoid=True):
convlayer = torch.nn.Sequential(
torch.nn.ConvTranspose2d(
inch, outch, kernel_size=kernel_size, stride=stride, padding=padding),
torch.nn.Sigmoid() if sigmoid else torch.nn.Sequential()
)
return convlayer
def deconv_leakrelu(inch, outch, kernel_size, stride=1, padding=1):
convlayer = torch.nn.Sequential(
torch.nn.ConvTranspose2d(
inch, outch, kernel_size=kernel_size, stride=stride, padding=padding),
torch.nn.BatchNorm2d(outch),
torch.nn.LeakyReLU()
)
return convlayer
def deconv_relu(inch, outch, kernel_size, stride=1, padding=1):
convlayer = torch.nn.Sequential(
torch.nn.ConvTranspose2d(
inch, outch, kernel_size=kernel_size, stride=stride, padding=padding),
torch.nn.BatchNorm2d(outch),
torch.nn.ReLU()
)
return convlayer