When fine-tuning a pretrained neural network, which layers are typically updated to adapt the model to a new task?
Think about which parts of the model capture general features versus task-specific features.
Typically, the early layers capture general features like edges or textures, so they are frozen. The final layers are updated to learn task-specific patterns.
When fine-tuning a pretrained model, which learning rate strategy is generally recommended?
Consider how sensitive pretrained weights are to big changes.
A smaller learning rate helps preserve useful pretrained features while allowing gradual adaptation to the new task.
What will be the output of the following PyTorch code snippet that freezes all layers except the last linear layer?
import torch import torch.nn as nn class SimpleModel(nn.Module): def __init__(self): super().__init__() self.features = nn.Sequential( nn.Linear(10, 20), nn.ReLU(), nn.Linear(20, 10) ) self.classifier = nn.Linear(10, 2) def forward(self, x): x = self.features(x) return self.classifier(x) model = SimpleModel() # Freeze all layers except classifier for param in model.features.parameters(): param.requires_grad = False trainable_params = [p for p in model.parameters() if p.requires_grad] print(len(trainable_params))
Count the number of parameters in the classifier layer that require gradients.
The classifier layer has weights and biases, so 2 parameter tensors require gradients. All feature layers are frozen.
During fine-tuning, you observe the training loss decreases steadily but validation accuracy plateaus early. What is the most likely explanation?
Think about what it means when training improves but validation does not.
When training loss improves but validation accuracy stops improving, the model is likely memorizing training data and not generalizing.
You try to freeze layers in a pretrained model but notice all parameters are still updating during training. Which code snippet correctly freezes the feature extractor layers in PyTorch?
Remember how to access parameters in a PyTorch module.
Only iterating over model.features.parameters() correctly sets requires_grad to False for all parameters. Other options are invalid or do not affect parameters.