Bird
Raised Fist0
TensorFlowml~20 mins

Pre-trained models (VGG, ResNet, MobileNet) in TensorFlow - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Pre-trained Models Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Model Choice
intermediate
2:00remaining
Choosing the right pre-trained model for image classification

You want to classify images of everyday objects on a mobile device with limited memory and processing power. Which pre-trained model is the best choice?

AVGG16 - It has a very deep architecture but is large and slow.
BMobileNetV2 - It is designed for mobile and embedded devices with low latency.
CResNet50 - It uses residual connections and is moderately sized.
DInceptionV3 - It has complex modules and is computationally heavy.
Attempts:
2 left
💡 Hint

Think about model size and speed for mobile devices.

❓ Predict Output
intermediate
2:00remaining
Output shape of a pre-trained VGG16 model

What is the output shape of the last layer of the VGG16 model loaded with include_top=True for ImageNet classification?

TensorFlow
import tensorflow as tf
model = tf.keras.applications.VGG16(include_top=True)
output_shape = model.output_shape
print(output_shape)
A(None, 7, 7, 512)
B(None, 224, 224, 3)
C(None, 1000)
D(None, 4096)
Attempts:
2 left
💡 Hint

Consider the final classification layer output for ImageNet classes.

❓ Hyperparameter
advanced
2:00remaining
Choosing the correct input size for ResNet50

You want to use the pre-trained ResNet50 model from TensorFlow Keras applications. What is the correct input image size to feed into this model?

A128x128 pixels
B299x299 pixels
C64x64 pixels
D224x224 pixels
Attempts:
2 left
💡 Hint

Check the standard input size for ResNet50 trained on ImageNet.

❓ Metrics
advanced
2:00remaining
Evaluating MobileNetV2 performance on a custom dataset

You fine-tune MobileNetV2 on a small dataset and want to evaluate its performance. Which metric is most appropriate to measure classification accuracy?

AAccuracy
BMean Squared Error (MSE)
CMean Absolute Error (MAE)
DRoot Mean Squared Error (RMSE)
Attempts:
2 left
💡 Hint

Think about the type of problem: classification or regression.

🔧 Debug
expert
3:00remaining
Debugging a shape mismatch error with ResNet50

You load ResNet50 with include_top=False and try to add a Dense layer with 1000 units directly after the model output. You get a shape mismatch error. Why?

TensorFlow
import tensorflow as tf
base_model = tf.keras.applications.ResNet50(include_top=False, input_shape=(224,224,3))
x = base_model.output
output = tf.keras.layers.Dense(1000, activation='softmax')(x)
model = tf.keras.Model(inputs=base_model.input, outputs=output)
AThe output of base_model is 4D (batch, height, width, channels), but Dense expects 2D input.
BThe input shape is incorrect; ResNet50 requires 299x299 images.
CDense layer cannot have 1000 units after a convolutional base.
DYou must set include_top=True to add Dense layers.
Attempts:
2 left
💡 Hint

Check the shape of the output tensor from the convolutional base.

Practice

(1/5)
1. Which of the following is a key benefit of using pre-trained models like VGG, ResNet, or MobileNet in TensorFlow?
easy
A. They require training from scratch for every new task.
B. They cannot be fine-tuned for new tasks.
C. They only work with text data, not images.
D. They save time by using models already trained on large datasets.

Solution

  1. Step 1: Understand what pre-trained models are

    Pre-trained models are AI models trained on large datasets like ImageNet before you use them.
  2. Step 2: Identify the main advantage

    Using these models saves time because you don't need to train from zero; you can use their learned features directly.
  3. Final Answer:

    They save time by using models already trained on large datasets. -> Option D
  4. Quick Check:

    Pre-trained models save time = B [OK]
Hint: Pre-trained means already trained, so saves time [OK]
Common Mistakes:
  • Thinking pre-trained models need full retraining
  • Believing they only work on text data
  • Assuming they cannot be fine-tuned
2. Which of the following is the correct way to load the MobileNetV2 pre-trained model in TensorFlow with weights trained on ImageNet?
easy
A. tf.keras.MobileNetV2(weights='imagenet')
B. tf.keras.applications.MobileNetV2(weights='imagenet')
C. tf.keras.applications.MobileNet(weights='imagenet')
D. tf.keras.applications.MobileNetV2(weights='random')

Solution

  1. Step 1: Recall the correct TensorFlow module for pre-trained models

    Pre-trained models are loaded from tf.keras.applications, not directly from tf.keras.
  2. Step 2: Check the correct model name and weights argument

    The correct model name is MobileNetV2 and weights='imagenet' loads pre-trained weights.
  3. Final Answer:

    tf.keras.applications.MobileNetV2(weights='imagenet') -> Option B
  4. Quick Check:

    Use tf.keras.applications + correct model name + weights='imagenet' = A [OK]
Hint: Use tf.keras.applications.ModelName(weights='imagenet') [OK]
Common Mistakes:
  • Using tf.keras.MobileNetV2 instead of tf.keras.applications.MobileNetV2
  • Using wrong model name like MobileNet instead of MobileNetV2
  • Setting weights='random' instead of 'imagenet'
3. What will be the output shape of the following code snippet using the ResNet50 model in TensorFlow?
import tensorflow as tf
model = tf.keras.applications.ResNet50(weights='imagenet')
input_shape = (1, 224, 224, 3)
sample_input = tf.random.uniform(input_shape)
output = model(sample_input)
print(output.shape)
medium
A. (1, 7, 7, 2048)
B. (224, 224, 3)
C. (1, 1000)
D. (1, 100)

Solution

  1. Step 1: Understand ResNet50 output for ImageNet weights

    ResNet50 with weights='imagenet' outputs predictions for 1000 classes, so output shape is (batch_size, 1000).
  2. Step 2: Check input batch size and output shape

    Input batch size is 1, so output shape is (1, 1000).
  3. Final Answer:

    (1, 1000) -> Option C
  4. Quick Check:

    ResNet50 output shape = (batch_size, 1000) = A [OK]
Hint: Output shape matches number of ImageNet classes (1000) [OK]
Common Mistakes:
  • Confusing output with input shape
  • Expecting feature map shape instead of final predictions
  • Assuming output has spatial dimensions
4. You tried to load the VGG16 model with this code:
model = tf.keras.applications.VGG16(weights='imagenet', include_top=False, input_shape=(28,28,3))

But got an error. What is the likely cause?
medium
A. Input shape must be at least 32x32 with 3 channels when include_top=False.
B. Weights='imagenet' is not supported for VGG16.
C. include_top=False cannot be used with input_shape argument.
D. VGG16 requires grayscale images, so 3 channels is wrong.

Solution

  1. Step 1: Check VGG16 input shape requirements

    When include_top=False, VGG16 requires input images at least 32x32 pixels with 3 color channels.
  2. Step 2: Verify input shape given

    Input shape (28,28,3) is smaller than 32x32x3 minimum when include_top=False, causing the error.
  3. Step 3: Identify common mistake

    Often error happens if input_shape is smaller than 32x32 or channels not 3. The question implies error due to input shape constraints.
  4. Final Answer:

    Input shape must be at least 32x32 with 3 channels when include_top=False. -> Option A
  5. Quick Check:

    VGG16 input shape min size = 32x32x3 [OK]
Hint: VGG16 needs input ≥32x32x3 if include_top=False [OK]
Common Mistakes:
  • Thinking weights='imagenet' is unsupported
  • Believing include_top=False forbids input_shape
  • Assuming VGG16 uses grayscale images
5. You want to build a fast image classifier for mobile devices using TensorFlow. Which pre-trained model should you choose to balance speed and accuracy?
hard
A. MobileNet, because it is designed for lightweight and fast inference.
B. ResNet50, because it uses residual connections for better training.
C. InceptionV3, because it has the most complex architecture.
D. VGG19, because it has the deepest layers and highest accuracy.

Solution

  1. Step 1: Understand model design goals

    VGG19 is large and slow, ResNet50 is accurate but heavier, MobileNet is optimized for mobile with smaller size and speed.
  2. Step 2: Match model to mobile device needs

    Mobile devices need fast, lightweight models, so MobileNet fits best for balancing speed and accuracy.
  3. Final Answer:

    MobileNet, because it is designed for lightweight and fast inference. -> Option A
  4. Quick Check:

    MobileNet = lightweight + fast for mobile [OK]
Hint: MobileNet is made for mobile speed and size [OK]
Common Mistakes:
  • Choosing VGG19 for mobile despite size
  • Assuming ResNet50 is fastest
  • Picking InceptionV3 without speed consideration
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard