0
0
TensorFlowml~10 mins

Feature extraction approach in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load a pre-trained MobileNetV2 model without the top classification layer.

TensorFlow
base_model = tf.keras.applications.MobileNetV2(input_shape=(224, 224, 3), include_top=[1], weights='imagenet')
Drag options to blanks, or click blank then click option'
ANone
BFalse
C'imagenet'
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Setting include_top=True loads the full model including classification layers, not suitable for feature extraction.
2fill in blank
medium

Complete the code to freeze the base model layers so they are not trainable.

TensorFlow
base_model.trainable = [1]
Drag options to blanks, or click blank then click option'
AFalse
BTrue
CNone
D'frozen'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting trainable=True will allow the base model to be trained, which is not desired in feature extraction.
3fill in blank
hard

Fix the error in the code to add a global average pooling layer after the base model.

TensorFlow
global_average_layer = tf.keras.layers.GlobalAveragePooling2D() 
features = global_average_layer([1].output)
Drag options to blanks, or click blank then click option'
Abase_model
Bmodel
Cinputs
Dfeatures
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the wrong variable like 'model' or 'inputs' instead of base_model.output.
4fill in blank
hard

Fill both blanks to create a new model that uses the base model input and the pooled features as output.

TensorFlow
model = tf.keras.Model(inputs=[1], outputs=[2])
Drag options to blanks, or click blank then click option'
Abase_model.input
Bfeatures
Cbase_model.output
Dinputs
Attempts:
3 left
💡 Hint
Common Mistakes
Using base_model.output as input or using base_model.output as output instead of pooled features.
5fill in blank
hard

Fill all three blanks to add a dense classification layer, compile the model, and specify the optimizer.

TensorFlow
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'])
Drag options to blanks, or click blank then click option'
A10
Bfeatures
Cbase_model.input
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong number of units in dense layer or wrong input/output tensors.