0
0
Computer Visionml~10 mins

Why pre-trained models save time in Computer Vision - Test Your Understanding

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 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'
Aload
Btrain
Cresnet18
Dfit
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'train' or 'fit' instead of a model name.
Trying to call 'load' which is not a model constructor.
2fill in blank
medium

Complete the code to freeze all layers of the pre-trained model to save training time.

Computer Vision
for param in model.[1]():
    param.requires_grad = False
Drag options to blanks, or click blank then click option'
Aparameters
Bchildren
Clayers
Dmodules
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'children()' which returns submodules, not parameters.
Using 'layers()' which is not a valid method.
3fill in blank
hard

Fix the error in the code to replace the last layer for transfer learning.

Computer Vision
import torch.nn as nn
model.fc = nn.[1](512, 10)
Drag options to blanks, or click blank then click option'
AConv2d
BDropout
CReLU
DLinear
Attempts:
3 left
💡 Hint
Common Mistakes
Using Conv2d which is for convolutional layers.
Using activation layers like ReLU or Dropout instead of Linear.
4fill in blank
hard

Fill both blanks to set the model to evaluation mode and disable gradient calculation.

Computer Vision
model.[1]()
with torch.[2]():
    outputs = model(inputs)
Drag options to blanks, or click blank then click option'
Aeval
Btrain
Cno_grad
Denable_grad
Attempts:
3 left
💡 Hint
Common Mistakes
Using model.train() instead of model.eval().
Using torch.enable_grad() which enables gradients.
5fill in blank
hard

Fill all three blanks to create a dictionary of layer names and their requires_grad status.

Computer Vision
grad_status = {name: param.[1] for name, param in model.[2]() if name.[3]('fc') == False}
Drag options to blanks, or click blank then click option'
Arequires_grad
Bnamed_parameters
Cendswith
Dstartswith
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'parameters()' instead of 'named_parameters()' which lacks names.
Using 'endswith' instead of 'startswith' to filter layer names.
Checking 'requires_grad' incorrectly.