转载地址:https://bbs.huaweicloud.com/forum/thread-105791-1-1.html
作者:yexi
-
MindIR概念介绍
MindIR的全称为MindSpore IR,是MindSpore的一种基于图表示的函数式IR,定义了可扩展的图结构以及算子的IR表示,消除了不同后端的模型差异,一般用于跨硬件平台执行推理任务。(来自课程PPT)
-
作业1
1. 任务
导出LeNet网络的MindIR格式模型。
2. 过程
根据官网https://www.mindspore.cn 中的安装教程在CPU环境的Windows10系统上安装MindSpore。
根据https://www.mindspore.cn/tutorial/training/zh-CN/r1.1/quick_start/quick_start.html 中的教程“实现一个图片分类应用”,使用LeNet模型对MNIST数据集进行分类,得到Checkpoint格式模型checkpoint_lenet-1_1875.ckpt。
根据https://www.mindspore.cn/tutorial/training/zh-CN/r1.1/use/save_model.html#mindir 中的“导出MindIR格式文件”内容,将所得的checkpoint_lenet-1_1875.ckpt模型文件转成MindIR格式,代码如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
-
作业2
1. 任务
训练一个ResNet50网络。使用训练好的checkpoint文件,导出MindIR格式模型。
2. 过程
继续使用https://www.mindspore.cn/tutorial/training/zh-CN/r1.1/quick_start/quick_start.html 中的代码模板,其中定义模型结构的代码需要改成ResNet50网络模型(可从https://gitee.com/mindspore/mindspore/blob/master/model_zoo/official/cv/resnet/src/resnet.py 中获取 ),使用的数据集改成hymenoptera数据集(下载地址为https://download.pytorch.org/tutorial/hymenoptera_data.zip ,需要删除训练集中ants文件夹下的一张.gif格式的图片)。训练修改后的程序得到Checkpoint格式模型。
同样根据https://www.mindspore.cn/tutorial/training/zh-CN/r1.1/use/save_model.html#mindir 中的“导出MindIR格式文件”内容,将所得的Checkpoint格式模型文件转成MindIR格式,代码如下所示:
1 2 3 4 5 6 7 8 9 10 |
|