用户工具

站点工具


模型参数的载入

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

后一修订版
前一修订版
模型参数的载入 [2019/12/03 13:56]
admin 创建
模型参数的载入 [2020/09/02 17:07] (当前版本)
218.104.204.98
行 4: 行 4:
 ====== 参数的筛选 ====== ====== 参数的筛选 ======
 pretrained_dict =... pretrained_dict =...
- 
 model_dict = model.state_dict() model_dict = model.state_dict()
  
行 22: 行 21:
 model.load_state_dict(model_dict) model.load_state_dict(model_dict)
  
 +====== 载入参数到指定设备 ======
 +
 +===== 1. cpu -> cpu或者gpu -> gpu =====
 +
 +
 + checkpoint = torch.load('​modelparameters.pth'​)
 + model.load_state_dict(checkpoint)
 +
 +===== 2. cpu -> gpu 1 =====
 +
 +''​
 +torch.load('​modelparameters.pth',​ map_location=lambda storage, loc: storage.cuda(1))
 +''​
 +
 +
 +===== 3. gpu 1 -> gpu 0 =====
 +
 +
 +''​torch.load('​modelparameters.pth',​ map_location={'​cuda:​1':'​cuda:​0'​})''​
 +===== 4. gpu -> cpu =====
 +
 +
 +''​torch.load('​modelparameters.pth',​ map_location=lambda storage, loc: storage)''​
 +
 +''​torch.load('​modelparameters.pth',​ map_location='​cpu'​)''​
  
模型参数的载入.1575352602.txt.gz · 最后更改: 2020/02/01 21:40 (外部编辑)