Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a pre-trained model in TensorFlow.
TensorFlow
base_model = tf.keras.applications.MobileNetV2(weights=[1], include_top=False)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using None means no pre-trained weights, so transfer learning benefits are lost.
Using dataset names like 'cifar10' is not valid for this parameter.
✗ Incorrect
Using 'imagenet' loads weights trained on a large dataset, which helps transfer learning.
2fill in blank
mediumComplete the code to freeze the base model layers so they are not trained.
TensorFlow
base_model.trainable = [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting trainable to True will retrain all layers, losing transfer learning speed benefits.
✗ Incorrect
Setting trainable to False freezes the layers, saving training time and data needs.
3fill in blank
hardFix the error in the code to add a new classification head after the base model.
TensorFlow
model = tf.keras.Sequential([
base_model,
tf.keras.layers.GlobalAveragePooling2D(),
tf.keras.layers.Dense([1], activation='softmax')
]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string like '10' causes an error.
Using None or 1 will not match the dataset classes.
✗ Incorrect
The Dense layer needs the number of classes as an integer, here 10 for classification.
4fill in blank
hardFill both blanks to compile the model with an optimizer and loss suitable for transfer learning.
TensorFlow
model.compile(optimizer=[1], loss=[2], metrics=['accuracy'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'mse' loss is for regression, not classification.
Using 'sgd' optimizer works but is slower to converge than 'adam'.
✗ Incorrect
Adam optimizer and categorical crossentropy loss are common choices for classification transfer learning.
5fill in blank
hardFill all three blanks to create a data pipeline that resizes images, batches them, and prefetches for performance.
TensorFlow
train_ds = train_ds.map(lambda x, y: (tf.image.resize(x, [1]), y)) train_ds = train_ds.batch([2]) train_ds = train_ds.prefetch(buffer_size=[3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong image size causes shape errors.
Batch size too large or too small affects training speed.
Not using prefetch or wrong buffer size slows data loading.
✗ Incorrect
Images are resized to 224x224, batch size is 32, and prefetch uses AUTOTUNE for best speed.