Challenge - 5 Problems
Feature Extraction Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of feature extraction with TensorFlow Hub
What is the shape of the output tensor after extracting features from a batch of 3 images using a TensorFlow Hub MobileNetV2 feature vector model?
TensorFlow
import tensorflow as tf import tensorflow_hub as hub model_url = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4" feature_extractor = hub.KerasLayer(model_url, input_shape=(224, 224, 3)) batch_images = tf.random.uniform([3, 224, 224, 3]) features = feature_extractor(batch_images) output_shape = features.shape print(output_shape)
Attempts:
2 left
💡 Hint
The MobileNetV2 feature vector outputs a 1280-dimensional vector per image.
✗ Incorrect
The feature extractor outputs a 2D tensor where each row corresponds to one image's feature vector. Since the batch size is 3, the output shape is (3, 1280).
❓ Model Choice
intermediate1:30remaining
Choosing a pre-trained model for feature extraction
You want to extract features from images to use in a new classifier. Which pre-trained model is best suited for feature extraction without the classification head?
Attempts:
2 left
💡 Hint
Feature extraction requires a model trained on images without the final classification layer.
✗ Incorrect
Using ResNet50 with include_top=False removes the classification head, allowing extraction of image features useful for new tasks.
❓ Hyperparameter
advanced2:00remaining
Effect of freezing layers during feature extraction
When using a pre-trained CNN for feature extraction, what is the effect of freezing all convolutional layers during training of a new classifier on top?
Attempts:
2 left
💡 Hint
Freezing layers means their weights stay fixed during training.
✗ Incorrect
Freezing convolutional layers keeps their learned features intact and reduces training time since fewer parameters update.
❓ Metrics
advanced1:30remaining
Evaluating feature extraction effectiveness
You extracted features from images using a pre-trained model and trained a new classifier. Which metric best indicates if the extracted features are useful for the classification task?
Attempts:
2 left
💡 Hint
The quality of features is reflected in how well the classifier performs on unseen data.
✗ Incorrect
Validation accuracy shows how well the classifier generalizes using the extracted features, indicating their usefulness.
🔧 Debug
expert2:30remaining
Debugging feature extraction output shape mismatch
You use a TensorFlow Hub feature extractor expecting output shape (None, 2048), but your code raises a shape mismatch error. Which code change fixes this?
TensorFlow
import tensorflow_hub as hub import tensorflow as tf feature_extractor = hub.KerasLayer('https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/5', input_shape=(224, 224, 3)) inputs = tf.random.uniform([5, 224, 224, 3]) features = feature_extractor(inputs) print(features.shape)
Attempts:
2 left
💡 Hint
The input_shape parameter expects the shape of a single image, excluding batch size.
✗ Incorrect
The input_shape should be (224, 224, 3) for single images; inputs must have batch dimension. This matches the model's expected input and output shapes.