当前位置:网站首页>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 ,
边栏推荐
- 深度剖析C语言指针
- 【MySQL】鎖
- Pointer advanced --- pointer array, array pointer
- sys.argv
- 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
- egg. JS project deployment online server
- China vanadium battery Market Research and future prospects report (2022 Edition)
- 堆排序详解
- Double pointeur en langage C - - modèle classique
- Rviz仿真时遇到机器人瞬间回到世界坐标原点的问题及可能原因
猜你喜欢
Restful API design specification
JVM 快速入门
Unified ordering background interface product description Chinese garbled
tree树的精准查询
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
MySQL learning record 11jdbcstatement object, SQL injection problem and Preparedstatement object
marathon-envs项目环境配置(强化学习模仿参考动作)
Bottom up - physical layer
Deep analysis of C language data storage in memory
C語言雙指針——經典題型
随机推荐
JVM performance tuning and practical basic theory - Part 1
pytorch训练好的模型在加载和保存过程中的问题
IOT -- interpreting the four tier architecture of the Internet of things
Analysis of pointer and array written test questions
Synchronized solves problems caused by sharing
电脑F1-F12用途
egg. JS directory structure
leetcode刷题 (5.29) 哈希表
2022.02.13 - NC002. sort
FairGuard游戏加固:游戏出海热潮下,游戏安全面临新挑战
tree树的精准查询
Cisp-pte practice explanation
vulnhub hackme: 1
游戏解包的危害及资源加密的重要性
logback1.3. X configuration details and Practice
Configuring OSPF load sharing for Huawei devices
Image fusion -- challenges, opportunities and Countermeasures
Online yaml to CSV tool
How to conduct interface test? What are the precautions? Nanny level interpretation
Online yaml to CSV tool