当前位置:网站首页>pytorch相同结构不同参数名模型加载权重
pytorch相同结构不同参数名模型加载权重
2022-06-13 08:51:00 【刀么克瑟拉莫】
- 因为声明的网络模型比保存的模型bn层多一个参数
num_batches_tracked
,所以跳过它
import torch, copy
net=yourNet()
state_dict = copy.deepcopy(net.state_dict())
keys=[]
for key in state_dict:
if(key.split('.')[-1] == 'num_batches_tracked'):
continue
keys.append(key)
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
paras=torch.load('weights.pth', map_location=device)
for k1,k2 in zip(keys, paras):
state_dict[k1] = paras[k2]
边栏推荐
- 3、 JS notes
- JS - print 99 multiplication table of the for cycle case
- Knowledge points related to system architecture 1
- File upload JS
- Three methods to make the scroll bar of div automatically scroll to the bottom
- 12. constructor explanation, explicit, initialization list
- 国债逆回购能开户吗,国债逆回购在APP上可以直接开通券商安全吗 ,买股票怎么网上开户
- JS wrapper object
- 2、 Three ways to write JS code
- Wrap dynamically created child elements in dynamically created structures
猜你喜欢
随机推荐
淘宝商品历史价格接口/商品历史价走势接口代码对接分享
Svg text stroke effect
About RSA encryption and decryption principle
JS array method
Screenshot of cesium implementation scenario
Diversified tables through TL table row consolidation
GBase 常见网络问题及排查方法
In order to resist the flood, the soldiers have been fighting for 89 hours. How many days and hours are there in total?
Basic use of cesium, including loading images, terrain, models, vector data, etc
JS array using the reduce() method
Vscode define code block -- define cursor position
JS - simple ATM of the for cycle case
Logstash configuration reference article
Redis分布式集群搭建
Vscode plug in
5、 Constant, variable
On the use of regular expressions (bracket problem)
Mobile terminal development I: basic concepts
Filebeat collects logs to elk
Wrap dynamically created child elements in dynamically created structures