Challenge - 5 Problems
GAN Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediateRole of Generator in a GAN
In a Generative Adversarial Network (GAN), what is the primary role of the generator?
Attempts:
2 left
💡 Hint
Think about which part of the GAN tries to fool the other part.
✗ Incorrect
The generator's job is to produce new data samples that look like the real data to fool the discriminator.
🧠 Conceptual
intermediateRole of Discriminator in a GAN
What is the main function of the discriminator in a GAN?
Attempts:
2 left
💡 Hint
This part acts like a judge deciding if data is real or fake.
✗ Incorrect
The discriminator learns to tell apart real data from the fake data produced by the generator.
❓ Predict Output
advancedOutput Shape of Generator Model
Given the following TensorFlow generator model code, what is the shape of the output tensor?
TensorFlow
import tensorflow as tf from tensorflow.keras import layers def make_generator_model(): model = tf.keras.Sequential() model.add(layers.Dense(7*7*256, use_bias=False, input_shape=(100,))) model.add(layers.BatchNormalization()) model.add(layers.LeakyReLU()) model.add(layers.Reshape((7, 7, 256))) model.add(layers.Conv2DTranspose(128, (5, 5), strides=(1, 1), padding='same', use_bias=False)) model.add(layers.BatchNormalization()) model.add(layers.LeakyReLU()) model.add(layers.Conv2DTranspose(64, (5, 5), strides=(2, 2), padding='same', use_bias=False)) model.add(layers.BatchNormalization()) model.add(layers.LeakyReLU()) model.add(layers.Conv2DTranspose(1, (5, 5), strides=(2, 2), padding='same', use_bias=False, activation='tanh')) return model generator = make_generator_model() output = generator(tf.random.normal([1, 100])) output_shape = output.shape
Attempts:
2 left
💡 Hint
Check the effect of Conv2DTranspose layers with strides on spatial dimensions.
✗ Incorrect
The generator reshapes to (7,7,256), then upsamples twice by factor 2, resulting in (28,28,1) output shape.
❓ Metrics
advancedInterpreting GAN Loss Values
During GAN training, the discriminator loss is very low (close to 0), and the generator loss is very high. What does this indicate about the training?
Attempts:
2 left
💡 Hint
Think about what a low discriminator loss means in terms of classification accuracy.
✗ Incorrect
A low discriminator loss means it easily classifies real vs fake, so the generator is not fooling it well.
🔧 Debug
expertIdentifying Error in GAN Training Loop
Consider this simplified GAN training loop snippet in TensorFlow. What error will occur when running this code?
TensorFlow
import tensorflow as tf def train_step(generator, discriminator, real_images, batch_size, noise_dim): noise = tf.random.normal([batch_size, noise_dim]) with tf.GradientTape() as gen_tape, tf.GradientTape() as disc_tape: generated_images = generator(noise, training=True) real_output = discriminator(real_images) fake_output = discriminator(generated_images) gen_loss = tf.keras.losses.BinaryCrossentropy(from_logits=True)(tf.ones_like(fake_output), fake_output) disc_loss = tf.keras.losses.BinaryCrossentropy(from_logits=True)(tf.ones_like(real_output), real_output) + \ tf.keras.losses.BinaryCrossentropy(from_logits=True)(tf.zeros_like(fake_output), fake_output) gradients_of_generator = gen_tape.gradient(gen_loss, generator.trainable_variables) gradients_of_discriminator = disc_tape.gradient(disc_loss, discriminator.trainable_variables) generator.optimizer.apply_gradients(zip(gradients_of_generator, generator.trainable_variables)) discriminator.optimizer.apply_gradients(zip(gradients_of_discriminator, discriminator.trainable_variables)) batch_size = 32 noise_dim = 100 real_images = tf.random.normal([batch_size, 28, 28, 1]) # Assume generator and discriminator are defined and compiled with optimizers train_step(generator, discriminator, real_images, batch_size, noise_dim)
Attempts:
2 left
💡 Hint
Check if the generator and discriminator have optimizers assigned.
✗ Incorrect
If generator and discriminator models are not compiled with optimizers, accessing .optimizer will be None causing AttributeError.
