-
Notifications
You must be signed in to change notification settings - Fork 0
/
wasserstein_critic.py
73 lines (64 loc) · 2.33 KB
/
wasserstein_critic.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
import torch
from torch import nn
import torchvision
## BUILDING DISCRIMINATOR
class Wasserstein_distance(nn.Module):
def __init__(self, channels_image, features_d):
super(Wasserstein_distance, self).__init__()
# Input: N * channels_image * 64 * 64
self.disc = nn.Sequential(
## ----------LAYER-1----------
nn.Conv2d(in_channels=channels_image,
out_channels=features_d,
kernel_size=4,
stride=2,
padding=1
), ## 32x32
nn.LeakyReLU(0.2),
## ----------LAYER-2----------
self.nn_block(
in_channels=features_d,
out_channels=features_d*2,
kernel_size=4,
stride=2,
padding=1
), ## 16x16
## ----------LAYER-3----------
self.nn_block(
in_channels=features_d*2,
out_channels=features_d*4,
kernel_size=4,
stride=2,
padding=1
), ## 8x8
## ----------LAYER-4----------
self.nn_block(
in_channels=features_d*4,
out_channels=features_d*8,
kernel_size=4,
stride=2,
padding=1
), ## 8x8
## ----------LAYER-5----------
nn.Conv2d(
in_channels=features_d*8,
out_channels=1,
kernel_size=4,
stride=2,
padding=0
), ## 1x1
)
def nn_block(self, in_channels, out_channels, kernel_size, stride, padding):
return nn.Sequential(
nn.Conv2d(in_channels=in_channels,
out_channels=out_channels,
kernel_size=kernel_size,
stride=stride,
padding=padding,
bias=False
),
nn.InstanceNorm2d(out_channels, affine=True),
nn.LeakyReLU(0.2)
)
def forward(self, x):
return self.disc(x)