当前位置:网站首页>What is the method to load the torch pre trained model for the mindspore model finetune?
What is the method to load the torch pre trained model for the mindspore model finetune?
2022-07-25 19:41:00 【Xiaole happy】
Migrating one mindspore Network of , existing torch edition , And there are already torch Pre trained weights . Training from scratch mindspore Your network is too time-consuming , I hope it can be loaded directly torch The weight of finetune. Is there any way to do it ?
Need to put torch Of checkpoint Turn it into MindSpore Format checkpoint. And then use MindSpore load checkpoint perform fune-tune Mission .
conversion checkpoint Please refer to the following code :
from mindspore.train.serialization import save_checkpointfrom mindspore import Tensorimport torchdef pytorch2mindspore('res18_py.pth'):
par_dict = torch.load('res18_py.pth')['state_dict']
new_params_list = []
for name in par_dict:
param_dict = {}
parameter = par_dict[name]
print('========================py_name',name)
if name.endswith('normalize.bias'):
name = name[:name.rfind('normalize.bias')]
name = name + 'normalize.beta'
elif name.endswith('normalize.weight'):
name = name[:name.rfind('normalize.weight')]
name = name + 'normalize.gamma'
elif name.endswith('.running_mean'):
name = name[:name.rfind('.running_mean')]
name = name + '.moving_mean'
elif name.endswith('.running_var'):
name = name[:name.rfind('.running_var')]
name = name + '.moving_variance'
print('========================ms_name',name)
param_dict['name'] = name
param_dict['data'] = Tensor(parameter.numpy())
new_params_list.append(param_dict)
save_checkpoint(new_params_list, 'res18_ms.ckpt')边栏推荐
- Binarysearch basic binary search
- A high efficiency 0-delay 0-copy QT player scheme based on Hisilicon 3559
- Security foundation 6 - vulnerability recurrence
- 基于PHP的中非南南合作信息交流平台网站建设
- Internal network planning and design of Yingcheng hospital
- Day7: ordered binary tree (binary search tree)
- University of California | feasible confrontation robust reinforcement learning for unspecified environments
- [artifact] screenshot + mapping tool snipaste
- [wp]ctfshow-web getting started - Explosion
- How to get started quickly in software testing
猜你喜欢

Istio exposes applications to the Internet

The JS paging plug-in supports tables, lists, text, and images

安全基础6 ---漏洞复现

连接数据库警告 Establishing SSL connection without server‘s identity verification is not recommended.

NPM semantic version control, solution console prop being mutated: "placement" error

Legal mix of collations for operation 'Union' (bug record)

虹科分享|如何解决勒索软件安全漏洞

Global configuration and page configuration of wechat applet development

KCon 2022 亮点及议程大揭秘!

高效生成接口文档好方法
随机推荐
VMware virtual machine download, installation and use tutorial
[CSAPP Practice Problem 2.32] tsub_ok(int x, int y)判断补码减法是否溢出
C语言学习日记3——realloc函数
Six axis sensor use learning record
Monitor MySQL based on MySQL exporter
手机端触摸图片slider轮播插件photoswipe.js
Bash does not add single quotes to your string
How to get started quickly in software testing
Wechat applet 10 - wechat template
Amrita Institute of Engineering | reinforcement active learning method for optimizing sampling in terms extraction of emotional analysis
Internal network planning and design of Yingcheng hospital
IP地址的概念
Authorized wireless communication standard
Analysis of CMS station building system of common PHP in China
浅谈接口加密
新瓶装老酒--近期APT32(海莲花)组织攻击活动样本分析
Ml programming skills:
Add a subtitle of 3D effect to the container
sentinel简单限流和降级demo问题记录
Siemens PLM Teamcenter download, installation and use tutorial