假设我们只保存了模型的参数(model.state_dict())到文件名为modelparameters.pth, model = Net()
cpu -> cpu或者gpu -> gpu:
checkpoint
= torch
.load
('modelparameters.pth')
model
.load_state_dict
(checkpoint
)
cpu -> gpu 1
torch
.load
('modelparameters.pth', map_location
=lambda storage
, loc
: storage
.cuda
(1))
gpu 1 -> gpu 0
torch
.load
('modelparameters.pth', map_location
={'cuda:1':'cuda:0'})
gpu -> cpu
torch
.load
('modelparameters.pth', map_location
=lambda storage
, loc
: storage
)
转载请注明原文地址:https://tech.qufami.com/read-26524.html