Complete the code to import the TensorFlow library.
import [1] as tf
TensorFlow is imported as tf to use its functions for building generative models.
Complete the code to define a simple generator model using Keras Sequential API.
model = tf.keras.Sequential([
tf.keras.layers.Dense(128, activation='relu', input_shape=(100,)),
tf.keras.layers.Dense(784, activation=[1])
])The output layer uses sigmoid activation to generate pixel values between 0 and 1 for new image data.
Fix the error in the code to compile the generator model with binary crossentropy loss.
model.compile(optimizer='adam', loss=[1])
Binary crossentropy loss is used for generative models producing binary or normalized outputs.
Fill both blanks to create a dictionary comprehension that maps noise vectors to generated images.
generated_images = {noise: model([1]) for noise in noises if noise.shape[0] [2] 100}Noise vectors are expanded to add batch dimension before passing to the model. We filter noises with batch size greater than 100.
Fill all three blanks to create a function that generates new data from random noise using the generator model.
def generate_new_data(model, [1]): noise = tf.random.normal(shape=([2], 100)) generated = model([3]) return generated
The function takes the number of samples, creates noise vectors of that size, passes noise to the model, and returns generated data.
