当前位置:网站首页>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')边栏推荐
- 滑雪手机端H5小游戏源码下载
- Istio exposes applications to the Internet
- Security Basics 4 - regular expressions
- Authorized wireless communication standard
- Selenium运行慢 - 通过设置selenium加载策略加快运行速度
- Split very long line of words into separate lines of max length
- SDL text display
- GBASE 8s UDR内存管理_02_mi_dalloc
- 高端旗舰投影仪选购指南:当贝X3 Pro、当贝F5观影更沉浸!
- Gbase 8s UDR memory management_ 03_ mi_ realloc
猜你喜欢

C merge set

Wechat campus maintenance and repair applet graduation design finished product (5) assignment of applet completion work

Binary tree visualization

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

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

Monitor MySQL based on MySQL exporter

Common misunderstandings caused by a time reporting assistant of Blue Bridge Cup basic questions
![[wp]ctfshow-web getting started - Explosion](/img/4b/6d8f4c044578382b9353d4d1c69c8f.png)
[wp]ctfshow-web getting started - Explosion

Scala基础【集合01】
![Scala foundation [set 01]](/img/6b/0f5da7ea923ef3aa436d7af9c4425c.png)
Scala foundation [set 01]
随机推荐
什么是唯心主义
Siemens-PLM-TeamCenter下载、安装、使用教程
GBASE 8s UDR内存管理_02_mi_dalloc
Software designer afternoon real topic: 2009-2022
How to get started quickly in software testing
Scala foundation [set 01]
连接数据库警告 Establishing SSL connection without server‘s identity verification is not recommended.
打印数据库返回的查询数据是null,或者是默认值。与数据库返回的值不相符
相机内参矩阵K和fov的相互转换
A high efficiency 0-delay 0-copy QT player scheme based on Hisilicon 3559
英诚医院内部网络规划与设计
Authorized wireless communication standard
Old wine in new bottles -- sample analysis of recent apt32 (sea Lotus) organizational attacks
03-树1 树的同构
How to analyze qiime2 after obtaining picrust2 results
An idea of solving div adapting to screen
Hongke shares | how to solve blackmail software security vulnerabilities
创意下拉多选js插件下载
微信小程序10-微搭模板
Wechat campus maintenance and repair applet graduation design finished product (7) Interim inspection report