Complete the code to load a pre-trained MobileNetV2 model without the top classification layer.
base_model = tf.keras.applications.MobileNetV2(input_shape=(224, 224, 3), include_top=[1], weights='imagenet')
Setting include_top=False loads the model without the final classification layers, which is essential for feature extraction.
Complete the code to freeze the base model layers so they are not trainable.
base_model.trainable = [1]Setting trainable = False freezes the layers, so their weights do not change during training.
Fix the error in the code to add a global average pooling layer after the base model.
global_average_layer = tf.keras.layers.GlobalAveragePooling2D()
features = global_average_layer([1].output)The global average pooling layer should be applied to the output of the base model, which is base_model.output.
Fill both blanks to create a new model that uses the base model input and the pooled features as output.
model = tf.keras.Model(inputs=[1], outputs=[2])
The new model takes the base model's input and outputs the pooled features for further processing.
Fill all three blanks to add a dense classification layer, compile the model, and specify the optimizer.
prediction_layer = tf.keras.layers.Dense([1], activation='softmax') outputs = prediction_layer([2]) model = tf.keras.Model(inputs=[3], outputs=outputs) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
The dense layer has 10 units for 10 classes, takes the pooled features as input, and the model uses the base model input.