当前位置:网站首页>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 ,
边栏推荐
- LDAP应用篇(4)Jenkins接入
- Leetcode question brushing (5.28) hash table
- [cloud native topic -45]:kubesphere cloud Governance - Introduction and overall architecture of enterprise container platform based on kubernetes
- MySQL learning record 07 index (simple understanding)
- Modify the video name from the name mapping relationship in the table
- vulnhub hackme: 1
- C語言雙指針——經典題型
- C language custom type: struct
- [MySQL] log
- Summary of phased use of sonic one-stop open source distributed cluster cloud real machine test platform
猜你喜欢

Unified ordering background interface product description Chinese garbled

vulnhub hackme: 1

Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures

生成器参数传入参数

Let the bullets fly for a while

优秀的软件测试人员,都具备这些能力

FairGuard游戏加固:游戏出海热潮下,游戏安全面临新挑战
![[MySQL] lock](/img/ce/9f8089da60d9b3a3f92a5e4eebfc13.png)
[MySQL] lock

MySQL learning record 10getting started with JDBC

个人电脑好用必备软件(使用过)
随机推荐
marathon-envs项目环境配置(强化学习模仿参考动作)
[MySQL] log
【MySQL】日志
synchronized 解决共享带来的问题
C语言深度解剖——C语言关键字
C language double pointer -- classic question type
Verrouillage [MySQL]
Use br to back up tidb cluster data to S3 compatible storage
【MySQL】数据库的存储过程与存储函数通关教程(完整版)
IoT -- 解读物联网四层架构
电脑清理,删除的系统文件
2022.02.13 - NC004. Print number of loops
Wincc7.5 download and installation tutorial (win10 system)
China vanadium battery Market Research and future prospects report (2022 Edition)
JS inheritance method
PLT in Matplotlib tight_ layout()
按位逻辑运算符
Pointer advanced --- pointer array, array pointer
PC easy to use essential software (used)
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