You want to create a model that generates new images by starting from random noise vectors. Which model type is most appropriate for this task?
Think about models designed to create new data rather than classify or predict sequences.
GANs are designed to generate new images by learning to produce outputs that look like real images, starting from random noise. CNN classifiers and RNNs are not designed for image generation, and linear regression is too simple for this task.
Given the following TensorFlow code snippet that generates an image from a noise vector using a simple generator model, what is the shape of the output tensor?
import tensorflow as tf import numpy as np noise_dim = 100 batch_size = 16 def simple_generator(): model = tf.keras.Sequential([ tf.keras.layers.Dense(7*7*64, use_bias=False, input_shape=(noise_dim,)), tf.keras.layers.BatchNormalization(), tf.keras.layers.LeakyReLU(), tf.keras.layers.Reshape((7, 7, 64)), tf.keras.layers.Conv2DTranspose(32, (5,5), strides=(2,2), padding='same', use_bias=False), tf.keras.layers.BatchNormalization(), tf.keras.layers.LeakyReLU(), tf.keras.layers.Conv2DTranspose(1, (5,5), strides=(2,2), padding='same', use_bias=False, activation='tanh') ]) return model model = simple_generator() noise = tf.random.normal([batch_size, noise_dim]) generated_images = model(noise) output_shape = generated_images.shape
Look at the final Conv2DTranspose layer's stride and output channels.
The model reshapes to (7,7,64), then upsamples twice by factor 2, resulting in (28,28). The last layer outputs 1 channel. Batch size is 16, so output shape is (16, 28, 28, 1).
You have trained an image generator model. You want to measure how realistic the generated images are compared to real images. Which metric is most suitable for this?
Consider metrics that capture both quality and variety of generated images.
Inception Score evaluates both how clear and diverse generated images are, making it a good metric for image generation quality. MSE and cross-entropy are training losses, not quality metrics. Classifier accuracy on generated images does not measure realism directly.
Consider this TensorFlow generator model code snippet. The training loss does not improve and generated images look like noise. What is the likely cause?
import tensorflow as tf def bad_generator(): model = tf.keras.Sequential([ tf.keras.layers.Dense(7*7*64, input_shape=(100,)), tf.keras.layers.BatchNormalization(), tf.keras.layers.ReLU(), tf.keras.layers.Reshape((7,7,64)), tf.keras.layers.Conv2DTranspose(32, (5,5), strides=(2,2), padding='same'), tf.keras.layers.BatchNormalization(), tf.keras.layers.ReLU(), tf.keras.layers.Conv2DTranspose(1, (5,5), strides=(2,2), padding='same', activation='sigmoid') ]) return model
Think about the typical pixel value range for generated images and activation functions.
Using 'sigmoid' outputs values between 0 and 1, but many GANs expect outputs scaled between -1 and 1 using 'tanh'. This mismatch can cause training instability and poor image quality. The other options do not cause this failure.
In a Generative Adversarial Network (GAN), what is the main purpose of the discriminator model during training?
Consider how the discriminator helps the generator improve.
The discriminator learns to distinguish real images from generated ones. Its feedback helps the generator improve by making generated images more realistic. It does not generate images or reduce dimensionality, nor does it directly optimize the generator's weights.
