-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.py
55 lines (44 loc) · 1.76 KB
/
Utils.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
import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
sys.path.append(os.path.dirname(__file__))
import torch
import torch.nn as nn
def conv(batchNorm, in_planes, out_planes, kernel_size=3, stride=1):
if batchNorm:
return nn.Sequential(
nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size,
stride=stride, padding=(kernel_size-1)//2, bias=False),
nn.BatchNorm2d(out_planes),
nn.LeakyReLU(0.05, inplace=True)
)
else:
return nn.Sequential(
nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size,
stride=stride, padding=(kernel_size-1)//2, bias=True),
nn.LeakyReLU(0.05, inplace=True)
)
def conv_no_lrelu(batchNorm, in_planes, out_planes, kernel_size=3, stride=1):
if batchNorm:
return nn.Sequential(
nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size,
stride=stride, padding=(kernel_size-1)//2, bias=False),
nn.BatchNorm2d(out_planes)
)
else:
return nn.Sequential(
nn.Conv2d(in_planes, out_planes, kernel_size=kernel_size,
stride=stride, padding=(kernel_size-1)//2, bias=True),
)
def predict_image(in_planes):
return nn.Conv2d(in_planes, 3, kernel_size=3, stride=1, padding=1, bias=False)
def deconv(in_planes, out_planes):
return nn.Sequential(
nn.ConvTranspose2d(in_planes, out_planes, kernel_size=4,
stride=2, padding=1, bias=False),
nn.LeakyReLU(0.05, inplace=True)
)
def crop_like(input, target):
if input.size()[2:] == target.size()[2:]:
return input
else:
return input[:, :, :target.size(2), :target.size(3)]