0
0
TensorFlowml~10 mins

Transfer learning for small datasets 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 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'
ATrue
BFalse
CNone
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting include_top=True loads the full model including the classification head, which is not suitable for transfer learning on new tasks.
2fill in blank
medium

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

TensorFlow
base_model.[1] = False
Drag options to blanks, or click blank then click option'
Afrozen
Btrain
Crequires_grad
Dtrainable
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect attribute names like 'frozen' or 'requires_grad' which do not exist in TensorFlow.
3fill in blank
hard

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

TensorFlow
x = base_model.output
x = tf.keras.layers.[1]()(x)
Drag options to blanks, or click blank then click option'
ADense
BFlatten
CGlobalAveragePooling2D
DDropout
Attempts:
3 left
💡 Hint
Common Mistakes
Using Dense or Flatten layers directly after the convolutional base without pooling can cause shape errors.
4fill in blank
hard

Fill both blanks to create a new model with the base model and a final dense layer for 5 classes.

TensorFlow
outputs = tf.keras.layers.Dense([1], activation=[2])(x)
model = tf.keras.Model(inputs=base_model.input, outputs=outputs)
Drag options to blanks, or click blank then click option'
A5
B'softmax'
C'relu'
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'relu' activation in the output layer or wrong number of units.
5fill in blank
hard

Fill all three blanks to compile the model with Adam optimizer, categorical crossentropy loss, and accuracy metric.

TensorFlow
model.compile(optimizer=[1], loss=[2], metrics=[[3]])
Drag options to blanks, or click blank then click option'
A'adam'
B'categorical_crossentropy'
C'accuracy'
D'mse'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean squared error loss or wrong metrics for classification.