0
0
Computer Visionml~10 mins

Fine-tuning approach 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 model for fine-tuning.

Computer Vision
from torchvision import models
model = models.resnet18(pretrained=[1])
Drag options to blanks, or click blank then click option'
A0
BFalse
CTrue
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using pretrained=False will initialize random weights, not useful for fine-tuning.
Passing None or 0 will cause errors or ignore pre-trained weights.
2fill in blank
medium

Complete the code to freeze all layers except the last fully connected layer.

Computer Vision
for param in model.parameters():
    param.[1] = False
Drag options to blanks, or click blank then click option'
Adetach
Bgrad
Ctrain
Drequires_grad
Attempts:
3 left
💡 Hint
Common Mistakes
Using grad or train attributes will cause errors or have no effect.
detach is a method, not an attribute to freeze parameters.
3fill in blank
hard

Fix the error in replacing the last layer to match 10 output classes.

Computer Vision
import torch.nn as nn
model.fc = nn.Linear(model.fc.in_features, [1])
Drag options to blanks, or click blank then click option'
A10
B0
C1
D100
Attempts:
3 left
💡 Hint
Common Mistakes
Using 100 or 1 will cause shape mismatch errors during training.
Using 0 will cause runtime errors.
4fill in blank
hard

Fill both blanks to set the optimizer to update only trainable parameters with learning rate 0.001.

Computer Vision
import torch.optim as optim
optimizer = optim.SGD([1], lr=[2])
Drag options to blanks, or click blank then click option'
Afilter(lambda p: p.requires_grad, model.parameters())
Bmodel.parameters()
C0.01
D0.001
Attempts:
3 left
💡 Hint
Common Mistakes
Passing all parameters causes frozen layers to update unnecessarily.
Using a too high learning rate like 0.01 may harm fine-tuning.
5fill in blank
hard

Fill all three blanks to complete the training loop for one epoch with loss calculation and optimizer step.

Computer Vision
model.train()
for inputs, labels in dataloader:
    optimizer.zero_grad()
    outputs = model([1])
    loss = criterion(outputs, [2])
    loss.[3]()
    optimizer.step()
Drag options to blanks, or click blank then click option'
Ainputs
Blabels
Cbackward
Dforward
Attempts:
3 left
💡 Hint
Common Mistakes
Passing labels to model instead of inputs causes errors.
Calling forward() on loss is invalid; use backward().