当前位置:网站首页>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 ,
边栏推荐
- PLT in Matplotlib tight_ layout()
- Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
- MySQL learning record 10getting started with JDBC
- Roguelike游戏成破解重灾区,如何破局?
- What is CSRF (Cross Site Request Forgery)?
- 堆排序详解
- egg. JS project deployment online server
- Visual implementation and inspection of visdom
- Precise query of tree tree
- @JsonBackReference和@JsonManagedReference(解决对象中存在双向引用导致的无限递归)
猜你喜欢
随机推荐
从表中名称映射关系修改视频名称
C language - bit segment
Introduction to backup and recovery Cr
sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
Circular reference of ES6 module
JS pure function
logback1.3. X configuration details and Practice
Colorlog结合logging打印有颜色的日志
tree树的精准查询
MySQL learning record 07 index (simple understanding)
2022 Inner Mongolia latest water conservancy and hydropower construction safety officer simulation examination questions and answers
Wincc7.5 download and installation tutorial (win10 system)
JVM 快速入门
角色动画(Character Animation)的现状与趋势
pcd转ply后在meshlab无法打开,提示 Error details: Unespected eof
PC easy to use essential software (used)
Huawei cloud OBS file upload and download tool class
电脑F1-F12用途
What is CSRF (Cross Site Request Forgery)?
Restore backup data on S3 compatible storage with tidb lightning