Skip to content

Commit

Permalink
6.3: fix issue about torchvision
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhikangNiu committed May 29, 2022
1 parent 2703dd0 commit 4e34c7c
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion source/第六章/6.3 模型微调-torchvision.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ model = models.resnet18(pretrained=True)
set_parameter_requires_grad(model, feature_extract)
# 修改模型
num_ftrs = model.fc.in_features
model.fc = nn.Linear(in_features=512, out_features=4, bias=True)
model.fc = nn.Linear(in_features=num_ftrs, out_features=4, bias=True)
```

之后在训练过程中,model仍会进行梯度回传,但是参数更新则只会发生在fc层。通过设定参数的requires_grad属性,我们完成了指定训练模型的特定层的目标,这对实现模型微调非常重要。
Expand Down

0 comments on commit 4e34c7c

Please sign in to comment.