16 classname = m.__class__.__name__
17 if classname.find(
'Conv') != -1:
18 m.weight.data.normal_(0.0, 0.02)
19 elif classname.find(
'BatchNorm') != -1:
20 m.weight.data.normal_(1.0, 0.02)
25 def __init__(self, ngpu):
26 super(_netG, self).__init__()
28 self.
main = nn.Sequential(
30 nn.ConvTranspose2d(nz, ngf * 8, 4, 1, 0, bias=
False),
31 nn.BatchNorm2d(ngf * 8),
34 nn.ConvTranspose2d(ngf * 8, ngf * 4, 4, 2, 1, bias=
False),
35 nn.BatchNorm2d(ngf * 4),
38 nn.ConvTranspose2d(ngf * 4, ngf * 2, 4, 2, 1, bias=
False),
39 nn.BatchNorm2d(ngf * 2),
42 nn.ConvTranspose2d(ngf * 2, ngf, 4, 2, 1, bias=
False),
46 nn.ConvTranspose2d(ngf, nc, 4, 2, 1, bias=
False),
51 def forward(self, input):
52 if self.
ngpu > 1
and isinstance(input.data, torch.cuda.FloatTensor):
53 output = nn.parallel.data_parallel(self.
main, input, range(self.
ngpu))
55 output = self.
main(input)
60 def __init__(self, ngpu):
61 super(_netD, self).__init__()
63 self.
main = nn.Sequential(
65 nn.Conv2d(nc, ndf, 4, 2, 1, bias=
False),
66 nn.LeakyReLU(0.2, inplace=
True),
68 nn.Conv2d(ndf, ndf * 2, 4, 2, 1, bias=
False),
69 nn.BatchNorm2d(ndf * 2),
70 nn.LeakyReLU(0.2, inplace=
True),
72 nn.Conv2d(ndf * 2, ndf * 4, 4, 2, 1, bias=
False),
73 nn.BatchNorm2d(ndf * 4),
74 nn.LeakyReLU(0.2, inplace=
True),
76 nn.Conv2d(ndf * 4, ndf * 8, 4, 2, 1, bias=
False),
77 nn.BatchNorm2d(ndf * 8),
78 nn.LeakyReLU(0.2, inplace=
True),
80 nn.Conv2d(ndf * 8, 1, 4, 1, 0, bias=
False),
84 def forward(self, input):
85 if self.
ngpu > 1
and isinstance(input.data, torch.cuda.FloatTensor):
86 output = nn.parallel.data_parallel(self.
main, input, range(self.
ngpu))
88 output = self.
main(input)
90 return output.view(-1, 1)