当前位置:网站首页>Problems in loading and saving pytorch trained models
Problems in loading and saving pytorch trained models
2022-07-06 08:33:00 【MAR-Sky】
stay gpu Finish training , stay cpu Load on
torch.save(model.state_dict(), PATH)# stay gpu Save after training
# stay cpu Loaded on the model of
model.load_state_dict(torch.load(PATH, map_location='cpu'))
stay cpu Finish training , stay gpu Load on
torch.save(model.state_dict(), PATH)# stay gpu Save after training
# stay cpu Loaded on the model of
model.load_state_dict(torch.load(PATH, map_location='cuda:0'))
Loading contents that need attention in use
When data is put into GPU, Models that need training should also be put into GPU
''' data_loader:pytorch Load data in '''
for i, sample in enumerate(data_loader): # Traverse the data by batch
image, target = sample # The return value of each batch loading
if CUDA:
image = image.cuda() # Input / output input gpu
target = target.cuda()
# print(target.size)
optimizer.zero_grad() # Optimization function
output = mymodel(image)
mymodel.to(torch.device("cuda"))
Multiple gpu Loading during training
Reference resources :https://blog.csdn.net/weixin_43794311/article/details/120940090
import torch.nn as nn
mymodel = nn.DataParallel(mymodel)
pytorch Medium nn Module USES nn.DataParallel Load the model into multiple GPU, We need to pay attention to , The weight saved by this loading method The parameters will Not used nn.DataParallel Before loading the keywords of the weight parameters saved by the model More than a "module.". Whether to use nn.DataParallel Load model , It may cause the following problems when loading the model next time ,
When there is one more in front of the weight parameter “module." when , The easiest way is to use nn.DataParallel Load model ,
边栏推荐
- Research Report on Market Research and investment strategy of microcrystalline graphite materials in China (2022 Edition)
- Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures
- Chrome浏览器的crash问题
- Use Alibaba icon in uniapp
- Restore backup data on S3 compatible storage with tidb lightning
- 2022.02.13 - NC003. Design LRU cache structure
- Permutation and combination function
- PLT in Matplotlib tight_ layout()
- JS native implementation shuttle box
- Let the bullets fly for a while
猜你喜欢
JVM performance tuning and practical basic theory - Part 1
JVM performance tuning and practical basic theory - Part 1
Deep learning: derivation of shallow neural networks and deep neural networks
根据csv文件某一列字符串中某个数字排序
MySQL learning record 10getting started with JDBC
2. File operation - write
C语言深度解剖——C语言关键字
2022.02.13 - NC002. sort
[MySQL] lock
Mobile phones and computers on the same LAN access each other, IIS settings
随机推荐
Use Alibaba icon in uniapp
Remote storage access authorization
Restore backup data on S3 compatible storage with br
Grayscale upgrade tidb operator
Verrouillage [MySQL]
Unified ordering background interface product description Chinese garbled
2022.02.13 - 238. Maximum number of "balloons"
hutool优雅解析URL链接并获取参数
优秀的软件测试人员,都具备这些能力
C language double pointer -- classic question type
Image fusion -- challenges, opportunities and Countermeasures
Function coritization
3. File operation 3-with
2022.02.13 - NC003. Design LRU cache structure
MySQL learning record 11jdbcstatement object, SQL injection problem and Preparedstatement object
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
移位运算符
查看局域网中电脑设备
Let the bullets fly for a while
Sort according to a number in a string in a column of CSV file