Code
Freezing Pretrained Parameters in PyTorch
In PyTorch, the parameters of a pretrained network can be explicitly frozen to prevent them from being updated during the fine-tuning process. This is accomplished by iterating through the specific module's parameters and setting the requires_grad attribute of each parameter tensor to False. By doing so, the autograd engine stops tracking operations on these parameters and skips gradient computation for them, effectively turning those layers into a static feature extractor.
0
1
Updated 2026-05-23
Tags
D2L
Dive into Deep Learning @ D2L