0
0
PyTorchml~20 mins

Image generation basics in PyTorch - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Image Generation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main role of the generator in a GAN?

In a Generative Adversarial Network (GAN), what is the primary function of the generator model?

ATo optimize the loss function of the discriminator
BTo classify images as real or fake
CTo create fake images that try to fool the discriminator
DTo preprocess the input images before training
Attempts:
2 left
💡 Hint

Think about which part of the GAN creates new images.

Predict Output
intermediate
2:00remaining
Output shape of generated images in a simple GAN

Consider the following PyTorch code snippet for a generator outputting images. What is the shape of the generated images tensor?

PyTorch
import torch
import torch.nn as nn

class SimpleGenerator(nn.Module):
    def __init__(self):
        super().__init__()
        self.fc = nn.Linear(100, 256*8*8)
        self.conv = nn.Sequential(
            nn.ConvTranspose2d(256, 128, 4, 2, 1),
            nn.ReLU(),
            nn.ConvTranspose2d(128, 3, 4, 2, 1),
            nn.Tanh()
        )
    def forward(self, z):
        x = self.fc(z)
        x = x.view(-1, 256, 8, 8)
        x = self.conv(x)
        return x

g = SimpleGenerator()
z = torch.randn(16, 100)
output = g(z)
output.shape
Atorch.Size([16, 3, 32, 32])
Btorch.Size([16, 100])
Ctorch.Size([16, 3, 16, 16])
Dtorch.Size([16, 256, 8, 8])
Attempts:
2 left
💡 Hint

Check how the ConvTranspose2d layers change the spatial dimensions.

Hyperparameter
advanced
2:00remaining
Choosing the latent vector size in image generation

Which statement best describes the effect of increasing the size of the latent vector (noise input) in a GAN generator?

ALatent vector size does not affect the generator's output
BLarger latent vectors always improve image quality without drawbacks
CSmaller latent vectors produce more diverse images
DLarger latent vectors can increase diversity but may make training harder
Attempts:
2 left
💡 Hint

Think about the trade-off between diversity and training complexity.

Metrics
advanced
2:00remaining
Evaluating image quality with Inception Score

What does a higher Inception Score (IS) indicate when evaluating generated images?

AInception Score measures only the speed of generation
BGenerated images are more diverse and look more like real images
CGenerated images have lower diversity but higher resolution
DGenerated images are less realistic but more varied
Attempts:
2 left
💡 Hint

IS combines image quality and variety in its score.

🔧 Debug
expert
3:00remaining
Identifying the cause of mode collapse in GAN training

During GAN training, the generator produces very similar images repeatedly, showing mode collapse. Which change is most likely to help reduce this problem?

AAdd noise to the discriminator inputs and use label smoothing
BIncrease the learning rate of the discriminator significantly
CUse a smaller batch size to reduce noise in gradients
DRemove dropout layers from the generator
Attempts:
2 left
💡 Hint

Think about techniques that stabilize GAN training and encourage diversity.