当前位置:网站首页>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 ,
边栏推荐
- Restore backup data on S3 compatible storage with tidb lightning
- C語言雙指針——經典題型
- VMware 虚拟化集群
- 从表中名称映射关系修改视频名称
- egg. JS getting started navigation: installation, use and learning
- Report on Market Research and investment prospects of China's silver powder industry (2022 Edition)
- [MySQL] log
- Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
- Permutation and combination function
- Precise query of tree tree
猜你喜欢

egg. JS getting started navigation: installation, use and learning

Process of obtaining the electronic version of academic qualifications of xuexin.com

Mobile phones and computers on the same LAN access each other, IIS settings

C语言深度解剖——C语言关键字

Restful API design specification

Online yaml to CSV tool

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

Precise query of tree tree

化不掉的钟薛高,逃不出网红产品的生命周期

Double pointeur en langage C - - modèle classique
随机推荐
Leetcode question brushing (5.28) hash table
Remote storage access authorization
sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
MySQL learning records 12jdbc operation transactions
On the inverse order problem of 01 knapsack problem in one-dimensional state
2022.02.13 - NC001. Reverse linked list
What is CSRF (Cross Site Request Forgery)?
Report on Market Research and investment prospects of China's silver powder industry (2022 Edition)
C语言双指针——经典题型
2022.02.13 - NC003. Design LRU cache structure
【Nvidia开发板】常见问题集 (不定时更新)
sys.argv
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
leetcode刷题 (5.29) 哈希表
sublime text中conda环境中plt.show无法弹出显示图片的问题
Bottom up - physical layer
根据csv文件某一列字符串中某个数字排序
The resources of underground pipe holes are tight, and the air blowing micro cable is not fragrant?
sys. argv
Golang force buckle leetcode 1020 Number of enclaves