Get startedGet started for free

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.

This exercise is part of the course

Deep Learning for Images with PyTorch

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

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()
Edit and Run Code