Imagine you have a tiny dataset of 100 images to classify. Why is transfer learning a good choice here?
Think about how pre-trained models help when data is limited.
Transfer learning leverages knowledge from a large dataset to help learn features, so the small dataset doesn't need to teach everything from zero.
Given this TensorFlow code snippet, what is the output shape of the model's predictions?
import tensorflow as tf base_model = tf.keras.applications.MobileNetV2(input_shape=(128,128,3), include_top=False, weights='imagenet') base_model.trainable = False model = tf.keras.Sequential([ base_model, tf.keras.layers.GlobalAveragePooling2D(), tf.keras.layers.Dense(5, activation='softmax') ]) output_shape = model.output_shape
Check the last Dense layer's output units.
The model outputs a vector of length 5 for each input, matching the Dense layer's units.
You want to fine-tune a pre-trained model on a small dataset. Which learning rate is most suitable?
Fine-tuning usually requires careful, small updates.
A very low learning rate prevents large changes to the pre-trained weights, preserving learned features while adapting to new data.
After training a transfer learning model on a small dataset, you see training accuracy at 95% but validation accuracy at 60%. What does this indicate?
Think about the difference between training and validation accuracy.
High training accuracy but low validation accuracy means the model learned training data too well but fails to generalize.
Consider this TensorFlow code snippet. It raises a ValueError when running. What is the cause?
import tensorflow as tf base_model = tf.keras.applications.ResNet50(weights='imagenet', include_top=False, input_shape=(64,64,3)) base_model.trainable = False model = tf.keras.Sequential([ base_model, tf.keras.layers.GlobalAveragePooling2D(), tf.keras.layers.Dense(10, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy') import numpy as np x = np.random.rand(32, 64, 64, 3) y = np.random.randint(0, 10, size=(32,)) model.fit(x, y, epochs=1)
Check the minimum input size requirements of ResNet50.
ResNet50 requires input images of at least 197x197 pixels when include_top=False; 64x64 is too small and causes a shape mismatch error.