Search⌘ K

Having Fun with the Generator Network

Explore how to interact with a trained GAN generator network by performing linear interpolation between latent vectors and semantic vector arithmetic. This lesson helps you understand how image outputs transform smoothly and how specific attributes can be modified, enhancing your practical skills in GAN image synthesis using PyTorch.

Now that our first image generator is trained, aren’t we curious about what it is capable of and how images are generated from random noise vectors? In this section, we will have some fun with the generator network. First, we will choose two random vectors and calculate the interpolation between them to see what images will be generated. Second, we will choose some exemplary vectors and perform arithmetic calculations on them to find out what changes appear in the generated samples.

First, we need a test version of the DCGAN code. Copy the original dcgan.py file to dcgan_test.py. Next, we need to make some Generator changes to our new file. First, we need to replace these lines of just the Generator class.

Python 3.10.4
netG = Generator().to(device)
netG.apply(weights_init)
print(netG)

We replace them with the following lines (we can either delete them or simply comment them out):

Python 3.10.4
netG = Generator()
negG.load_state_dict(torch.load(os.path.join(OUT_PATH, 'netG_24.pth')))
netG.to(device)

Next, we need to remove (or comment out) the weights_init, ...