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.
Bu egzersiz
Deep Learning for Images with PyTorch
kursunun bir parçasıdırEgzersiz talimatları
- Create a random noise tensor of shape
num_images_to_generateby16, the input noise size you used to train the generator, and assign it tonoise. - Generate images by passing the noise to the generator and assign them to
fake. - Inside the for loop, slice
faketo extract thei-th image and assign it toimage_tensor. - Permute
image_tensor's dimensions from (color, height, width) to (hight, width, color) and assign the output toimage_tensor_permuted.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
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()