0
0
PyTorchml~10 mins

torchvision pre-trained models in PyTorch - 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 ResNet18 model from torchvision.

PyTorch
import torchvision.models as models
model = models.[1](pretrained=True)
Drag options to blanks, or click blank then click option'
Aalexnet
Bvgg16
Cresnet18
Ddensenet121
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different model function like vgg16 instead of resnet18.
Forgetting to set pretrained=True to load pre-trained weights.
2fill in blank
medium

Complete the code to set the model to evaluation mode.

PyTorch
model = models.resnet18(pretrained=True)
model.[1]()
Drag options to blanks, or click blank then click option'
Apredict
Btrain
Cfit
Deval
Attempts:
3 left
💡 Hint
Common Mistakes
Calling train() instead of eval(), which keeps the model in training mode.
Using a non-existent method like predict().
3fill in blank
hard

Fix the error in the code to correctly load a pre-trained VGG16 model.

PyTorch
import torchvision.models as models
model = models.vgg16([1]=True)
Drag options to blanks, or click blank then click option'
Apretrained
Bweights
Cload_pretrained
Duse_pretrained
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'weights' instead of 'pretrained' in older torchvision versions.
Using incorrect argument names like 'load_pretrained' or 'use_pretrained'.
4fill in blank
hard

Fill both blanks to create a dictionary of model names and their corresponding pre-trained model functions.

PyTorch
models_dict = {
    'resnet': models.[1],
    'alexnet': models.[2]
}
Drag options to blanks, or click blank then click option'
Aresnet18
Bvgg16
Calexnet
Ddensenet121
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up model function names or using unrelated models.
Using the same option for both blanks.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps model names to their pre-trained model instances, filtering only models with names longer than 6 characters.

PyTorch
model_names = ['resnet18', 'vgg16', 'alexnet', 'densenet121']
models_dict = {
    [1]: models.[2](pretrained=True)
    for [3] in model_names if len([1]) > 6
}
Drag options to blanks, or click blank then click option'
Aname
Cmodel
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not matching the variable names in the condition and comprehension.