直接在GPU上加载:
pretrain = torch.load(opt.pretrain_path)
model.load_state_dict(pretrain['state_dict'])
将GPU模型加载在CPU上:
pretrain = torch.load(opt.pretrain_path, map_location=lambda storage, loc:
storage) from collections import OrderedDict new_state_dict = OrderedDict() for
k, v in pretrain.items(): if k=='state_dict': state_dict=OrderedDict() for keys
in v: name = keys[7:]# remove `module.` state_dict[name] = v[keys]
new_state_dict[k]=state_dict else: new_state_dict[k] = v
model.load_state_dict(new_state_dict['state_dict'])

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信