| 15 | |
| 16 | |
| 17 | def saveImage(generator,epoch,): |
| 18 | noise = torch.randn(size = (16,config.LATENT_DIM)).to(config.DEVICE) |
| 19 | # fixed labels |
| 20 | y_ = (torch.rand(16, 1) * config.NUM_CLASSES).type(torch.LongTensor) |
| 21 | y_fixed = torch.zeros(16, config.NUM_CLASSES) |
| 22 | y_fixed = y_fixed.scatter_(1, y_.view(16, 1), 1) |
| 23 | |
| 24 | gen_imgs = generator(noise, y_fixed).view(-1, config.CHANNELS,config.IMG_SIZE,config.IMG_SIZE) |
| 25 | |
| 26 | save_image(gen_imgs.data, 'save' + '/%d.png' % (epoch)) |
| 27 | |
| 28 | |
| 29 | def gradient_penalty(critic, real, fake, device): |