当前位置:网站首页>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')边栏推荐
- Improvement of wechat applet 28 hot search list ①
- Binary tree visualization
- 高效生成接口文档好方法
- C# 合并集合
- ML的编程技巧:
- Software designer afternoon real topic: 2009-2022
- Bash does not add single quotes to your string
- University of California | feasible confrontation robust reinforcement learning for unspecified environments
- The finished product of wechat campus maintenance and repair applet graduation design (1) development outline
- Heavy! The new book "deep learning in geometry" was released, which was jointly written by imperial Institute of technology /deepmind and other figures ml Daniel. The 160 page PDF expounds the basic p
猜你喜欢

微信小程序开发之网络数据请求

高效生成接口文档好方法

Monitor MySQL based on MySQL exporter

Is there a "fingerprint" in the structure of AAAI 2022 | Gan? Generating network structure from forged image traceability

sentinel简单限流和降级demo问题记录

C # add multi line and multi column text watermark in word

Binarysearch basic binary search

滑雪手机端H5小游戏源码下载

创意下拉多选js插件下载

binarySearch基础二分查找
随机推荐
Mobile phone touch picture slider rotation plug-in photoswipe.js
北航等《深度学习事件抽取》文献综述论文,27页pdf阐述当前趋势
[hdlbits questions] Verilog language (3) modules: hierarchy section
Authorized wireless communication standard
Improvement of wechat applet 28 hot search list ①
Hash undirected graph visualization
leetcode刷题:动态规划07(不同的二叉搜索树)
数字信息化(先枚举假设,再看是否满足条件)(1089 狼人杀-简单版)
ERROR: role “admin“ cannot be dropped because some objects depend on itDETAIL:
Research and application of servo driver in robot
Wechat campus maintenance and repair applet graduation design finished product (7) Interim inspection report
Wxss template style and WXS scripting language for wechat applet development
Univariate function integration_ Partial integral method
Kcon 2022 highlights and agenda revealed!
How to be a self disciplined person?
ERROR: role “admin“ cannot be dropped because some objects depend on itDETAIL:
Empire CMS whole station | mobile number /qq lianghao mall source code | suitable for mobile terminal
Yyds dry inventory how to locate browser page crash
[wp]ctfshow-web introductory information collection
High number_ Chapter 3 learning experience and summary of multiple integral