跳至内容
Knowledge Base
用户工具
登录
站点工具
搜索
工具
显示页面
修订记录
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
您在这里:
start
»
模型参数的载入
您的足迹:
模型参数的载入
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
====== strict选项 ====== 总结:用strict=False进行加载模型,则“能塞则塞,不能塞则丢”。load一般是依据key来加载的,一旦有key不匹配则出错。如果设置strict=False,则直接忽略不匹配的key,对于匹配的key则进行正常的赋值。 ====== 参数的筛选 ====== pretrained_dict =... model_dict = model.state_dict() # 1. filter out unnecessary keys pretrained_dict = {k: v for k, vin pretrained_dict.items() if k inmodel_dict} # 2. overwrite entries in the existing state dict model_dict.update(pretrained_dict) # 3. load the new state 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')''
模型参数的载入.txt
· 最后更改: 2020/09/02 17:07 由
218.104.204.98
页面工具
显示页面
修订记录
反向链接
回到顶部