提交 b5eca1cc 编写于 作者: Q QingChuanWS

.md更新

上级 398328c0
......@@ -8,7 +8,7 @@ Github ID: [yangqings](https://github.com/yangqings) E-mail: yangqingsheng12@ou
# 概述
`Tensorflow Lite Micro`` TensorFlow Lite `针对MCU的实验性端口,专门用于在微控制器和其他只有几千字节内存的设备上运行机器学习模型。
`Tensorflow Lite Micro` ` TensorFlow Lite ` 针对MCU的实验性端口,专门用于在微控制器和其他只有几千字节内存的设备上运行机器学习模型。
# 1. 建立与转换模型
......@@ -18,7 +18,7 @@ Github ID: [yangqings](https://github.com/yangqings) E-mail: yangqingsheng12@ou
## 1.1 模型转换
将一个已训练好的 TensorFlow 模型转换为可以在嵌入式设备中运行的Tensorflow Lite模型可以使用 [TensorFlow Lite 转换器 Python API](https://tensorflow.google.cn/lite/microcontrollers/build_convert) 。它能够将模型转换成 [`FlatBuffer`](https://google.github.io/flatbuffers/) 格式,减小模型规模,并修改模型以使用 TensorFlow Lite 支持的运算。
将一个已训练好的 TensorFlow 模型转换为可以在嵌入式设备中运行的 Tensorflow Lite 模型可以使用 [TensorFlow Lite 转换器 Python API](https://tensorflow.google.cn/lite/microcontrollers/build_convert) 。它能够将模型转换成 [`FlatBuffer`](https://google.github.io/flatbuffers/) 格式,减小模型规模,并修改模型以使用 TensorFlow Lite 支持的运算。
### 1.1.1 量化
......@@ -107,7 +107,7 @@ unsigned int converted_model_tflite_len = 18200;
#include "tensorflow/lite/micro/examples/micro_speech/micro_features/model.h"
```
- [`model.h`](https://github.com/QingChuanWS/tensorflow/tree/master/tensorflow/lite/micro_speech/micro_features/model.h) 包含存储为 `char` 数组的模型。阅读 [“构建与转换模型”](https://tensorflow.google.cn/lite/microcontrollers/build_convert)来了解如何将 Tensorflow Lite 模型转换为该格式。
- [`model.h`](https://github.com/QingChuanWS/tensorflow/tree/master/tensorflow/lite/micro_speech/micro_features/model.h) 包含存储为 `char` 数组的模型。阅读[“构建与转换模型”](https://tensorflow.google.cn/lite/microcontrollers/build_convert)来了解如何将 Tensorflow Lite 模型转换为该格式。
- [`micro_model_settings.h`](https://github.com/QingChuanWS/tensorflow/tree/master/tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.h) 定义与模型相关的各种常量。
### 1.3.2 设置日志记录
......@@ -283,13 +283,14 @@ make -f tensorflow/lite/micro/tools/make/Makefile generate_projects
成功运行之后会打印`--tensorflow lite micro source file extract successful--`字样,并在对应的`tflitemicro_path`路径下生成`Source`文件夹存放生成的tensorflow Lite Micro源文件。
## 2. 将源文件加入KEIL工程并生成.lib
## 2.2 将源文件加入 KEIL 工程并生成 .lib
新建目标芯片的KEIL工程(本次示例以ARM Cortex M4为例),将Source目录下的`tensorflow``third_party`文件夹拷贝到KEIL工程的根目录下,并添加`tensorflow`目录下除`lite/micro/kernels`以及`lite/micro/tools`文件夹以外的所有源文件(包含.c和.cc),例如下图所示:
新建目标芯片的KEIL工程(本次示例以 ARM Cortex M4 为例),将Source目录下的`tensorflow``third_party`文件夹拷贝到KEIL工程的根目录下,并添加`tensorflow`目录下除`lite/micro/kernels`以及`lite/micro/tools`文件夹以外的所有源文件(包含.c和.cc),例如下图所示:
<div align=center>
<img src="image/lib文件目录.png" width=80% />
</div>
**注意**
在添加`tensorflow/lite/micro/kernel`目录下的源文件时需要区分`reference`算子和应用`CMSIS-NN`加速之后的算子,`tensorflow/lite/micro/kernel`文件夹内容如下图中所示:
......@@ -309,7 +310,9 @@ make -f tensorflow/lite/micro/tools/make/Makefile generate_projects
1. 添加`tensorflow/lite/micro/kernel/`中的全部算子;
2. 无需添加`tensorflow/lite/micro/tools`文件夹下的源文件。
同时采用compiler version 6编译器并关闭Microlib:
**注:如果使用的是 ARM Cortex M4 以上的 MCU 的话,建议采用 CMSIS-NN 算子来生成 lib 库,可以获得较大的性能提升。**
同时采用 compiler version 6 编译器并关闭 Microlib:
<div align=center>
<img src="image/编译器配置.png" width=80% />
......@@ -327,5 +330,4 @@ make -f tensorflow/lite/micro/tools/make/Makefile generate_projects
<img src="image/配置include和优化等级等.png" width=80% />
</div>
最后点击编译链接之后,即可在工程根目录的`Objects`文件夹下生成ARM Cortex M4对应的.lib库,其他内核型号的tflite_micro库以此类推。
最后点击编译链接之后,即可在工程根目录的 `Objects` 文件夹下生成 ARM Cortex M4 对应的 .lib 库,其他内核型号的 tflite_micro 库以此类推。
......@@ -22,11 +22,13 @@ tflite_micro
其中,KEIL 文件夹中放置了针对 KEIL 编程环境需要额外添加的源文件,如果使用的是 KEIL 编程环境则需要将其中的源文件一同加入工程。
ARM_CortexM4_lib 和 ARM_CortexM7_lib 两个文件夹中存放了针对 Cortex M4、M7 平台预先优化、编译好的 tensorflow_lite_micro.lib 库,优化后的性能数据可以参考附录部分;这样做的目的是:如果在开发过程中使用了 ARM Cortex M4 或 M7 系列的芯片可以直接使用对应的 tensorflow_lite_micro.lib 库,并包含相关的头文件,可以极大的简化神经网络任务的部署流程。
ARM_CortexM4_lib 和 ARM_CortexM7_lib 两个文件夹中存放了针对 Cortex M4、M7 平台预先优化编译好的 tensorflow_lite_micro.lib 库,优化后的性能数据可以参考附录部分;如果在开发过程中使用了 ARM Cortex M4 或 M7 系列的芯片可以直接使用对应的 tensorflow_lite_micro.lib 库,并包含相关的头文件,可以极大的简化神经网络任务的部署流程。
## 3.移植案例
[TFlite_Micro_Component_User_Guide.md](./TFlite_Micro_Component_User_Guide.md) 中提供了本组件的基本使用流程以及上述 .lib 库的制作流程,可以在使用之前进行参考
参考[Neclue STM32L496RG案例](../../../board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TFlite_Micro_Demo移植参考指南(Keil版).md)
## 3.组件使用案例
基于本组件我们以 STM32L496RG 为例设计了行人检测案例,具体使用流程可参考[Neclue STM32L496RG案例](../../../board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TFlite_Micro_Demo移植参考指南(Keil版).md)
## 4. 附录:Tensorflow Lite Micro 性能优化情况
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册