当前位置:网站首页>Torch weight to mindspore

Torch weight to mindspore

2022-06-23 10:43:00 leo0308

0 Preface

because torch Ease of use and flexibility , A lot of research work is based on torch Realized .
However, in practical applications or other reasons, it is necessary to migrate to mindspore when , We all want to reuse directly torch Pre trained weights .
Of course mindspore turn torch It's the same thing .

1 Method

In short , It's actually a mapping process . The weight saved is actually a dict, Contains the name of the weight and the specific value , However, the organizational form of different frameworks will be different .
The difference is reflected in 2 spot : First, the naming organization of names is different , Such as torch in batchnorm The weight suffix of is generally .weight and .bias, and mindspore It is beta and gamma; Second, the storage format is different .
For the first difference , We need to list their weights separately , Match their names according to the rules .
For the second difference , We need to use it. torch and mindspore Each provides an interface for loading or saving weights , Treat the weight as dict This intermediate result , Then it can be processed with their own interfaces .

2 Implementation code

import torch
from mindspore.train import save_checkpoint, load_checkpoint
原网站

版权声明
本文为[leo0308]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231031008535.html