| 330 | |
| 331 | class Generator(nn.Module): |
| 332 | def __init__(self, ngpu): |
| 333 | super(Generator, self).__init__() |
| 334 | self.ngpu = ngpu |
| 335 | self.main = nn.Sequential( |
| 336 | # input is Z, going into a convolution |
| 337 | nn.ConvTranspose2d( nz, ngf * 8, 4, 1, 0, bias=False), |
| 338 | nn.BatchNorm2d(ngf * 8), |
| 339 | nn.ReLU(True), |
| 340 | # state size. ``(ngf*8) x 4 x 4`` |
| 341 | nn.ConvTranspose2d(ngf * 8, ngf * 4, 4, 2, 1, bias=False), |
| 342 | nn.BatchNorm2d(ngf * 4), |
| 343 | nn.ReLU(True), |
| 344 | # state size. ``(ngf*4) x 8 x 8`` |
| 345 | nn.ConvTranspose2d( ngf * 4, ngf * 2, 4, 2, 1, bias=False), |
| 346 | nn.BatchNorm2d(ngf * 2), |
| 347 | nn.ReLU(True), |
| 348 | # state size. ``(ngf*2) x 16 x 16`` |
| 349 | nn.ConvTranspose2d( ngf * 2, ngf, 4, 2, 1, bias=False), |
| 350 | nn.BatchNorm2d(ngf), |
| 351 | nn.ReLU(True), |
| 352 | # state size. ``(ngf) x 32 x 32`` |
| 353 | nn.ConvTranspose2d( ngf, nc, 4, 2, 1, bias=False), |
| 354 | nn.Tanh() |
| 355 | # state size. ``(nc) x 64 x 64`` |
| 356 | ) |
| 357 | |
| 358 | def forward(self, input): |
| 359 | return self.main(input) |