Aan de slagGa gratis aan de slag

Generating images

Now that you have designed and trained your GAN, it's time to evaluate the quality of the images it can generate. For a start, you will perform a visual inspection to see if the generation resemble the Pokemons at all. To do this, you will create random noise as input for the generator, pass it to the model and plot the outputs.

The Deep Convolutional Generator with trained weights is available to you as gen. torch and matplotlib.pyplot as plt are already imported for you.

Deze oefening maakt deel uit van de cursus

Deep Learning for Images with PyTorch

Cursus bekijken

Oefeninstructies

  • Create a random noise tensor of shape num_images_to_generate by 16, the input noise size you used to train the generator, and assign it to noise.
  • Generate images by passing the noise to the generator and assign them to fake.
  • Inside the for loop, slice fake to extract the i-th image and assign it to image_tensor.
  • Permute image_tensor's dimensions from (color, height, width) to (hight, width, color) and assign the output to image_tensor_permuted.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

num_images_to_generate = 5
# Create random noise tensor
noise = ____

# Generate images
with torch.no_grad():
    fake = ____
print(f"Generated tensor shape: {fake.shape}")
    
for i in range(num_images_to_generate):
    # Slice fake to select i-th image
    image_tensor = ____
    # Permute the image dimensions
    image_tensor_permuted = ____
    plt.imshow(image_tensor_permuted)
    plt.show()
Code bewerken en uitvoeren