0
0
TensorFlowml~20 mins

Feature extraction approach in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Feature Extraction Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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)
A(3, 1280)
B(224, 224, 3)
C(3, 1001)
D(1, 1280)
Attempts:
2 left
💡 Hint
The MobileNetV2 feature vector outputs a 1280-dimensional vector per image.
Model Choice
intermediate
1: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?
AA fully connected network trained on tabular data
BResNet50 with include_top=True
CResNet50 with include_top=False
DA randomly initialized CNN
Attempts:
2 left
💡 Hint
Feature extraction requires a model trained on images without the final classification layer.
Hyperparameter
advanced
2: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?
AThe convolutional layers' weights do not update, speeding up training and preserving learned features.
BThe convolutional layers' weights update, allowing the model to learn new features from scratch.
CThe model will overfit immediately due to frozen layers.
DThe model will not train because frozen layers cause errors.
Attempts:
2 left
💡 Hint
Freezing layers means their weights stay fixed during training.
Metrics
advanced
1: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?
ATraining loss of the pre-trained model
BValidation accuracy of the new classifier
CNumber of layers in the pre-trained model
DSize of the input images
Attempts:
2 left
💡 Hint
The quality of features is reflected in how well the classifier performs on unseen data.
🔧 Debug
expert
2: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)
AChange input_shape to (None, 224, 224, 3) in KerasLayer
BResize input images to (299, 299, 3) before passing to feature_extractor
CUse a different model URL that outputs shape (None, 1280)
DChange input_shape to (224, 224, 3) and ensure inputs have batch size dimension
Attempts:
2 left
💡 Hint
The input_shape parameter expects the shape of a single image, excluding batch size.