0
0
Computer Visionml~10 mins

Pre-trained models (ResNet, VGG, EfficientNet) in Computer Vision - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load a pre-trained ResNet50 model from torchvision.

Computer Vision
import torchvision.models as models
model = models.[1](pretrained=True)
Drag options to blanks, or click blank then click option'
Aefficientnet_b0
Bresnet50
Cvgg16
Dalexnet
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a model name that does not match ResNet50, like vgg16 or alexnet.
Forgetting to set pretrained=True to load pre-trained weights.
2fill in blank
medium

Complete the code to replace the final classification layer of a VGG16 model for 10 classes.

Computer Vision
import torch.nn as nn
import torchvision.models as models
model = models.vgg16(pretrained=True)
num_ftrs = model.classifier[6].in_features
model.classifier[6] = nn.[1](num_ftrs, 10)
Drag options to blanks, or click blank then click option'
ADropout
BConv2d
CReLU
DLinear
Attempts:
3 left
💡 Hint
Common Mistakes
Using Conv2d or ReLU instead of Linear for the final layer.
Not matching the output features to the number of classes.
3fill in blank
hard

Fix the error in the code to load EfficientNet-B0 pre-trained model from torchvision.

Computer Vision
import torchvision.models as models
model = models.[1](weights=models.EfficientNet_B0_Weights.IMAGENET1K_V1)
Drag options to blanks, or click blank then click option'
Aefficientnet_b0
Befficientnet_b1
Cresnet50
Dvgg16
Attempts:
3 left
💡 Hint
Common Mistakes
Using resnet50 or vgg16 instead of efficientnet_b0.
Incorrect weights enum for the model.
4fill in blank
hard

Fill both blanks to freeze all parameters of a pre-trained ResNet18 model.

Computer Vision
import torchvision.models as models
model = models.resnet18(pretrained=True)
for param in model.[1]():
    param.[2] = False
Drag options to blanks, or click blank then click option'
Aparameters
Bchildren
Crequires_grad
Dgrad
Attempts:
3 left
💡 Hint
Common Mistakes
Using children() instead of parameters() to freeze layers.
Setting grad instead of requires_grad.
5fill in blank
hard

Fill all three blanks to create a dictionary that maps model names to their pre-trained loading functions.

Computer Vision
import torchvision.models as models
model_loaders = {
    '[1]': models.[2],
    '[3]': models.vgg16,
}
Drag options to blanks, or click blank then click option'
Aresnet50
Cvgg16
Defficientnet_b0
Attempts:
3 left
💡 Hint
Common Mistakes
Using function names as keys instead of strings.
Mismatching keys and function names.