Bird
Raised Fist0
Computer Visionml~20 mins

Pre-trained models (ResNet, VGG, EfficientNet) in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Pre-trained Model Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the main advantage of using pre-trained models

Why do we often use pre-trained models like ResNet, VGG, or EfficientNet instead of training a model from scratch?

AThey always require more data and time to train than new models.
BThey allow faster training and better performance by using knowledge from large datasets.
CThey are simpler models with fewer layers, so easier to understand.
DThey only work for black and white images, not color images.
Attempts:
2 left
💡 Hint

Think about how learning from previous experience helps you solve new problems faster.

Predict Output
intermediate
2:00remaining
Output shape after passing an image through a pre-trained ResNet

Given a batch of 8 RGB images of size 224x224 passed through a pre-trained ResNet50 model (without the final classification layer), what is the shape of the output tensor?

Computer Vision
import torch
import torchvision.models as models

model = models.resnet50(pretrained=True)
model = torch.nn.Sequential(*list(model.children())[:-1])  # Remove final layer

input_tensor = torch.randn(8, 3, 224, 224)
output = model(input_tensor)
output_shape = output.shape
A(8, 512, 7, 7)
B(8, 1000)
C(8, 3, 224, 224)
D(8, 2048, 1, 1)
Attempts:
2 left
💡 Hint

Check the last convolutional layer output channels and spatial dimensions after pooling.

Model Choice
advanced
2:00remaining
Choosing the best pre-trained model for mobile deployment

You want to deploy an image classification model on a mobile device with limited memory and processing power. Which pre-trained model is the best choice?

AResNet50 - medium size but heavier than EfficientNet
BVGG19 - very deep and large model
CEfficientNet - balances accuracy and efficiency
DResNet152 - very deep with many layers
Attempts:
2 left
💡 Hint

Think about models designed for efficiency and smaller size.

Hyperparameter
advanced
2:00remaining
Adjusting learning rate when fine-tuning a pre-trained model

When fine-tuning a pre-trained VGG16 model on a new dataset, which learning rate strategy is most appropriate?

AUse a very low learning rate (e.g., 0.0001) to avoid destroying learned features
BUse a very high learning rate (e.g., 0.1) to speed up training
CUse the same learning rate as training from scratch (e.g., 0.01)
DUse no learning rate because the model is pre-trained
Attempts:
2 left
💡 Hint

Think about how big changes affect already learned knowledge.

Metrics
expert
2:00remaining
Interpreting accuracy differences between pre-trained models

You fine-tune ResNet50 and EfficientNet-B0 on the same dataset. ResNet50 achieves 85% accuracy, EfficientNet-B0 achieves 88%. What is the most likely reason for this difference?

AEfficientNet-B0 has a better architecture that balances depth, width, and resolution.
BResNet50 was trained with a higher learning rate causing overfitting.
CEfficientNet-B0 uses fewer parameters, so it always performs better.
DResNet50 is older and cannot learn new datasets.
Attempts:
2 left
💡 Hint

Consider model design principles and efficiency.

Practice

(1/5)
1. Which of the following is a key advantage of using pre-trained models like ResNet, VGG, or EfficientNet in computer vision tasks?
easy
A. They reduce the size of the input images automatically.
B. They save training time by using knowledge from large datasets.
C. They only work for text data, not images.
D. They always require training from scratch for every new task.

Solution

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

    Pre-trained models are trained on large datasets and learn useful features that can be reused.
  2. Step 2: Identify the benefit in context

    Using these models saves time because you don't need to train from scratch for every new task.
  3. Final Answer:

    They save training time by using knowledge from large datasets. -> Option B
  4. Quick Check:

    Pre-trained models save time = D [OK]
Hint: Pre-trained means already trained on big data [OK]
Common Mistakes:
  • Thinking pre-trained models need full retraining
  • Confusing image and text data applicability
  • Assuming input size changes automatically
2. Which of the following is the correct way to load a pre-trained ResNet model in PyTorch?
easy
A. model = torch.load('resnet50')
B. model = torchvision.load_resnet50()
C. model = torchvision.models.ResNet50(weights='imagenet')
D. model = torchvision.models.resnet50(pretrained=True)

Solution

  1. Step 1: Recall PyTorch syntax for loading pre-trained models

    In PyTorch, pre-trained models are loaded via torchvision.models with pretrained=True argument.
  2. Step 2: Check each option

    model = torchvision.models.resnet50(pretrained=True) uses correct function and argument. Others are incorrect or invalid syntax.
  3. Final Answer:

    model = torchvision.models.resnet50(pretrained=True) -> Option D
  4. Quick Check:

    PyTorch pre-trained flag = pretrained=True [OK]
Hint: Use pretrained=True in torchvision.models [OK]
Common Mistakes:
  • Using torch.load for model architecture
  • Wrong function names like load_resnet50
  • Incorrect argument names like weights='imagenet'
3. Consider this PyTorch code snippet using a pre-trained VGG16 model:
import torchvision.models as models
model = models.vgg16(pretrained=True)
print(type(model.features))
What will be the output type of model.features?
medium
A. <class 'torch.nn.Linear'>
B. <class 'torch.nn.ModuleList'>
C. <class 'torch.nn.Sequential'>
D. <class 'torch.nn.Conv2d'>

Solution

  1. Step 1: Understand VGG16 model structure in PyTorch

    VGG16's feature extractor is implemented as a torch.nn.Sequential container of layers.
  2. Step 2: Identify the type of model.features

    model.features groups convolutional layers in a Sequential module, so its type is torch.nn.Sequential.
  3. Final Answer:

    <class 'torch.nn.Sequential'> -> Option C
  4. Quick Check:

    VGG features = Sequential container [OK]
Hint: VGG features are in Sequential container [OK]
Common Mistakes:
  • Confusing Sequential with ModuleList
  • Thinking features is a single layer like Linear or Conv2d
  • Not knowing PyTorch container types
4. You try to fine-tune a pre-trained EfficientNet model but get an error: AttributeError: module 'torchvision.models' has no attribute 'efficientnet'. What is the most likely cause?
medium
A. Your torchvision version is outdated and does not include EfficientNet.
B. You forgot to import torch.
C. EfficientNet models are not available in PyTorch.
D. You need to set pretrained=True to access EfficientNet.

Solution

  1. Step 1: Understand the error message

    The error says torchvision.models has no attribute 'efficientnet', meaning the function is missing.
  2. Step 2: Check common causes

    EfficientNet was added in newer torchvision versions. An outdated version lacks it.
  3. Final Answer:

    Your torchvision version is outdated and does not include EfficientNet. -> Option A
  4. Quick Check:

    Missing attribute = outdated torchvision [OK]
Hint: Check torchvision version for model availability [OK]
Common Mistakes:
  • Assuming import torch fixes model availability
  • Thinking EfficientNet is not in PyTorch at all
  • Confusing pretrained flag with missing attribute
5. You want to build an image classifier for a small dataset with limited computing power. Which pre-trained model is the best choice to balance accuracy and efficiency?
hard
A. EfficientNet, because it scales well and is efficient for small data.
B. VGG16, because it is simple but very large and slow.
C. ResNet50, because it is very deep and accurate but heavy.
D. Train a new model from scratch for best results.

Solution

  1. Step 1: Consider dataset size and computing power

    Small data and limited power require efficient models to avoid overfitting and long training.
  2. Step 2: Compare model characteristics

    ResNet50 is accurate but heavy; VGG16 is large and slow; EfficientNet is designed for efficiency and good accuracy.
  3. Step 3: Choose the best fit

    EfficientNet balances accuracy and efficiency, making it ideal for small datasets and limited resources.
  4. Final Answer:

    EfficientNet, because it scales well and is efficient for small data. -> Option A
  5. Quick Check:

    Efficiency + accuracy = EfficientNet [OK]
Hint: EfficientNet balances speed and accuracy well [OK]
Common Mistakes:
  • Choosing heavy models for small data
  • Ignoring efficiency for limited computing power
  • Thinking training from scratch is always better