Complete the code to load a pre-trained MobileNetV2 model without the top 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 useful for transfer learning.
Complete the code to freeze the base model layers so they are not trainable.
base_model.[1] = False
Setting trainable = False freezes the layers so their weights do not update during training.
Fix the error in the code to add a global average pooling layer after the base model.
x = base_model.output
x = tf.keras.layers.[1]()(x)The GlobalAveragePooling2D layer reduces the spatial dimensions by averaging, which is common after convolutional base models.
Fill both blanks to create a new model with the base model and a final dense layer for 5 classes.
outputs = tf.keras.layers.Dense([1], activation=[2])(x) model = tf.keras.Model(inputs=base_model.input, outputs=outputs)
The final dense layer should have 5 units for 5 classes and use 'softmax' activation for multi-class classification.
Fill all three blanks to compile the model with Adam optimizer, categorical crossentropy loss, and accuracy metric.
model.compile(optimizer=[1], loss=[2], metrics=[[3]])
Adam optimizer is popular for training. Categorical crossentropy is used for multi-class classification. Accuracy measures how often predictions are correct.