转载地址:https://bbs.huaweicloud.com/forum/thread-118013-1-1.html
作者:franco52576
版本号截图
硬件平台与操作系统:
Windows8.1 -X64
Intel i5-5200 CPU
RAM:16G
体验内容学习笔记
看了Mindspore 1.2.0的最新版本,发现有了一键模型迁移,简直太有用了。
赶快看一下教程如何迁移训练好的pytorch模型。
首先需要使用第三方框架脚本MindConverter。
MindConverter是一款用于将PyTorch(ONNX)、TensorFlow(PB)模型转换到MindSpore模型定义脚本以及权重文件的工具。结合转换报告的信息,用户只需对转换后的脚本进行微小的改动,即可实现快速迁移。此工具为MindInsight的子模块,安装MindInsight后,即可使用MindConverter。
所以如果想转换PyTorch模型,最好先转成ONNX模型再进行迁移。
MindConverter提供命令行(Command-line interface, CLI)的使用方式,命令如下。
usage: mindconverter [-h] [--version] [--in_file IN_FILE]
[--model_file MODEL_FILE] [--shape SHAPE [SHAPE ...]]
[--input_nodes INPUT_NODES [INPUT_NODES ...]]
[--output_nodes OUTPUT_NODES [OUTPUT_NODES ...]]
[--output OUTPUT] [--report REPORT]
optional arguments:
-h, --help show this help message and exit
--version show program version number and exit
--in_file IN_FILE Specify path for script file to use AST schema to do
script conversation.
--model_file MODEL_FILE
Tensorflow(.pb) or ONNX(.onnx) model file path is
expected to do script generation based on graph
schema. When `--in_file` and `--model_file` are both
provided, use AST schema as default.
--shape SHAPE [SHAPE ...]
Optional, expected input tensor shape of
`--model_file`. It is required when use graph based
schema. Both order and number should be consistent
with `--input_nodes`. Usage: --shape 1,512 1,512
--input_nodes INPUT_NODES [INPUT_NODES ...]
Optional, input node(s) name of `--model_file`. It is
required when use graph based schema. Both order and
number should be consistent with `--shape`. Usage:
--input_nodes input_1:0 input_2:0
--output_nodes OUTPUT_NODES [OUTPUT_NODES ...]
Optional, output node(s) name of `--model_file`. It is
required when use graph based schema. Usage:
--output_nodes output_1:0 output_2:0
--output OUTPUT Optional, specify path for converted script file
directory. Default output directory is `output` folder
in the current working directory.
--report REPORT Optional, specify report directory. Default is
converted script directory.
对于TensorFlow模型脚本迁移 同样使用指定--model_file
、--shape
、--input_nodes
、--output_nodes
进行脚本迁移。看起来十分方便
顺便提示一下
新特性介绍 MindSpore开源周年狂欢,量子机器学习与深度分子模拟等巨量新特性来袭,发布新开源TinyMS工具包!中
三、易用性 教程超链接有点问题哦
##################4.13增#######################
本来是打算试验一下MindConverte 来转换Pytorch 模型的,后来安装的时候发现不支持CPU,于是只好放弃
于是只能通过经典的手写体识别来体验一下新版本了。
看看速度上和精度上是不是有明显差别。
先输出一下数据集,顺便看看最新版本是不是升级成功了,嗯挺好!
接下来看一下loss曲线和精度的结果。
先来对比一下loss的结果:上图为1.1 下图为1.2
可以看到除了部分波动外,其余 还是差不多的。
那再来看看精度的对比结果。同样上图为1.1,下图为1.2
可以看到精度提升的速度有了明显的变换,
不知道这是机器之间的差异,还是1.2里对底层的处理方式有了一些改动呢?欢迎大家讨论。
同时也期待在后面的使用和测试中找到这个问题的答案!