提交 85bc1362 编写于 作者: T TonyWang222

update ms guidelines

Change-Id: I018c48d459cc7dc9474401e578344cad806782b4
Signed-off-by: NTonyWang222 <wangtongyu6@huawei.com>
上级 39208c93
......@@ -54,8 +54,32 @@ MindSpore Lite是一款AI引擎,它提供了面向不同硬件设备AI模型
**图 1** 使用MindSpore Lite进行模型推理的开发流程
![how-to-use-mindspore-lite](figures/01.png)
主要开发步骤包括模型的准备、读取、编译、推理和释放,具体开发过程及细节请见下文的开发步骤及示例。
进入主要流程之前需要先引用相关的头文件,并编写函数生成随机的输入,具体如下:
```c
#include <stdlib.h>
#include <stdio.h>
#include "mindspore/model.h"
//生成随机的输入
int GenerateInputDataWithRandom(OH_AI_TensorHandleArray inputs) {
for (size_t i = 0; i < inputs.handle_num; ++i) {
float *input_data = (float *)OH_AI_TensorGetMutableData(inputs.handle_list[i]);
if (input_data == NULL) {
printf("MSTensorGetMutableData failed.\n");
return OH_AI_STATUS_LITE_ERROR;
}
int64_t num = OH_AI_TensorGetElementNum(inputs.handle_list[i]);
const int divisor = 10;
for (size_t j = 0; j < num; j++) {
input_data[j] = (float)(rand() % divisor) / divisor; // 0--0.9f
}
}
return OH_AI_STATUS_SUCCESS;
}
```
然后进入主要的开发步骤,具括包括模型的准备、读取、编译、推理和释放,具体开发过程及细节请见下文的开发步骤及示例。
1. 模型准备。
需要的模型可以直接下载,也可以通过模型转换工具获得。
......@@ -101,8 +125,8 @@ MindSpore Lite是一款AI引擎,它提供了面向不同硬件设备AI模型
return OH_AI_STATUS_LITE_ERROR;
}
// 加载与编译模型,模型的类型为OH_AI_ModelTypeMindIR
int ret = OH_AI_ModelBuildFromFile(model, argv[1], OH_AI_ModelTypeMindIR, context);
// 加载与编译模型,模型的类型为OH_AI_MODELTYPE_MINDIR
int ret = OH_AI_ModelBuildFromFile(model, argv[1], OH_AI_MODELTYPE_MINDIR, context);
if (ret != OH_AI_STATUS_SUCCESS) {
printf("OH_AI_ModelBuildFromFile failed, ret: %d.\n", ret);
OH_AI_ModelDestroy(&model);
......@@ -193,7 +217,7 @@ MindSpore Lite是一款AI引擎,它提供了面向不同硬件设备AI模型
dl
)
```
- 使用ohos-sdk交叉编译,需要对CMake设置native工具链路径,即:`-DCMAKE_TOOLCHAIN_FILE="/xxx/ohos-sdk/linux/native/build/cmake/ohos.toolchain.camke"`
- 使用ohos-sdk交叉编译,需要对CMake设置native工具链路径,即:`-DCMAKE_TOOLCHAIN_FILE="/xxx/native/build/cmake/ohos.toolchain.camke"`
- 工具链默认编译64位的程序,如果要编译32位,需要添加:`-DOHOS_ARCH="armeabi-v7a"`
......@@ -214,3 +238,7 @@ MindSpore Lite是一款AI引擎,它提供了面向不同硬件设备AI模型
output data is:
0.000018 0.000012 0.000026 0.000194 0.000156 0.001501 0.000240 0.000825 0.000016 0.000006 0.000007 0.000004 0.000004 0.000004 0.000015 0.000099 0.000011 0.000013 0.000005 0.000023 0.000004 0.000008 0.000003 0.000003 0.000008 0.000014 0.000012 0.000006 0.000019 0.000006 0.000018 0.000024 0.000010 0.000002 0.000028 0.000372 0.000010 0.000017 0.000008 0.000004 0.000007 0.000010 0.000007 0.000012 0.000005 0.000015 0.000007 0.000040 0.000004 0.000085 0.000023
```
## 相关实例
针对MindSpore Lite 的使用,有以下相关实例可供参考:
- [简易MSLite教程](https://gitee.com/openharmony/third_party_mindspore/tree/master/mindspore/lite/examples/quick_start_c)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册