Complete the code to import the necessary library for building a neural network model.
from tensorflow import [1]
The keras module from TensorFlow is used to build neural network models including autoencoders.
Complete the code to define the input shape for the autoencoder model.
input_img = keras.Input(shape=[1])The input shape for grayscale images of size 28x28 pixels is (28, 28, 1).
Fix the error in the code to compile the autoencoder model with the correct loss function.
autoencoder.compile(optimizer='adam', loss='[1]')
For autoencoders reconstructing images, the mean squared error (mse) loss is commonly used.
Fill both blanks to create the encoder part of the autoencoder using convolution and pooling layers.
x = keras.layers.Conv2D(32, (3, 3), activation='relu', padding='same')(input_img) x = keras.layers.[1]((2, 2), padding='same')(x)
The encoder uses Conv2D followed by MaxPooling2D to reduce image size while extracting features.
Fill all three blanks to build the decoder part with upsampling and convolution layers to reconstruct the image.
x = keras.layers.[1]((2, 2))(encoded) x = keras.layers.Conv2D(32, (3, 3), activation='relu', padding='[2]')(x) decoded = keras.layers.Conv2D(1, (3, 3), activation='[3]', padding='same')(x)
The decoder upsamples the encoded features using UpSampling2D, then applies convolution with same padding and a sigmoid activation to reconstruct the image pixels between 0 and 1.