0
0
TensorFlowml~10 mins

Freezing and unfreezing layers 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 freeze all layers in a TensorFlow Keras model.

TensorFlow
for layer in model.layers:
    layer.[1] = False
Drag options to blanks, or click blank then click option'
Afrozen
Btrainable
Cactive
Dlocked
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent property like 'frozen' or 'locked'.
Confusing the value True/False for freezing.
2fill in blank
medium

Complete the code to unfreeze only the last layer of the model.

TensorFlow
model.layers[-1].[1] = True
Drag options to blanks, or click blank then click option'
Aactive
Bfrozen
Ctrainable
Dlocked
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to set a property that does not exist.
Forgetting to set trainable to True.
3fill in blank
hard

Fix the error in the code to freeze all layers before compiling the model.

TensorFlow
for layer in model.layers:
    layer.[1] = False
model.compile(optimizer='adam', loss='categorical_crossentropy')
Drag options to blanks, or click blank then click option'
Atrainable
Bfrozen
Cactive
Dlocked
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent property like 'frozen'.
Setting the property after compiling the model.
4fill in blank
hard

Fill both blanks to freeze all layers except the last one.

TensorFlow
for layer in model.layers[:[1]]:
    layer.[2] = False
Drag options to blanks, or click blank then click option'
Atrainable
B-1
Cfrozen
Dlocked
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect slice indices.
Using a wrong property name to freeze layers.
5fill in blank
hard

Fill all three blanks to freeze the first two layers and unfreeze the rest.

TensorFlow
for layer in model.layers[:[1]]:
    layer.[2] = False
for layer in model.layers[[3]:]:
    layer.trainable = True
Drag options to blanks, or click blank then click option'
Atrainable
B2
Dfrozen
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong slice indices.
Using incorrect property names.