You want to generate images conditioned on class labels using TensorFlow. Which model architecture is best suited for this task?
Think about how the model can use label information to guide generation.
Conditional GANs (cGANs) explicitly use class labels as input to both generator and discriminator, enabling the generator to produce images conditioned on those labels. Standard GANs and VAEs without conditioning cannot control output classes. A feedforward network is for classification, not generation.
Consider this TensorFlow code snippet for a conditional generator model:
import tensorflow as tf
noise = tf.random.normal([16, 100])
labels = tf.one_hot(tf.random.uniform([16], maxval=10, dtype=tf.int32), depth=10)
input_vector = tf.concat([noise, labels], axis=1)
model = tf.keras.Sequential([
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(28 * 28 * 1, activation='sigmoid'),
tf.keras.layers.Reshape((28, 28, 1))
])
output = model(input_vector)
print(output.shape)What will be printed?
Check the batch size and the final reshape layer.
The input batch size is 16. The model outputs a tensor reshaped to (28, 28, 1) per example. So the output shape is (16, 28, 28, 1).
When training a conditional GAN in TensorFlow, which loss function combination is most appropriate to encourage the generator to produce realistic images conditioned on labels?
Think about the typical GAN loss and how label smoothing helps.
Binary Cross-Entropy loss is standard for GANs to distinguish real vs fake. Label smoothing helps stabilize training by preventing the discriminator from becoming too confident. MSE or Huber losses are not typical for GAN adversarial losses.
Which metric is best suited to quantitatively evaluate the quality and diversity of images generated by a conditional GAN trained on labeled image data?
Consider a metric that measures both quality and diversity without needing paired images.
Inception Score evaluates both the quality and diversity of generated images using a pretrained classifier. MSE and SSIM require paired images and do not measure diversity. Classifier accuracy on generated images alone does not reflect generation quality.
You trained a conditional GAN in TensorFlow, but the generator produces nearly identical images regardless of input labels. What is the most likely cause?
Think about how the generator receives conditioning information.
If the generator does not receive label information concatenated with noise, it cannot learn to produce different outputs conditioned on labels, causing mode collapse. The discriminator alone having labels is insufficient. Batch size and learning rate issues cause other problems but not this specific failure.
