Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
不穿格子衫的农民
TencentOS Tiny
提交
b5eca1cc
T
TencentOS Tiny
项目概览
不穿格子衫的农民
/
TencentOS Tiny
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TencentOS Tiny
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b5eca1cc
编写于
2月 06, 2021
作者:
Q
QingChuanWS
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
.md更新
上级
398328c0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
15 addition
and
11 deletion
+15
-11
components/ai/tflite_micro/TFlite_Micro_Component_User_Guide.md
...ents/ai/tflite_micro/TFlite_Micro_Component_User_Guide.md
+10
-8
components/ai/tflite_micro/readme.md
components/ai/tflite_micro/readme.md
+5
-3
未找到文件。
components/ai/tflite_micro/TFlite_Micro_Component_User_Guide.md
浏览文件 @
b5eca1cc
...
...
@@ -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 库以此类推。
components/ai/tflite_micro/readme.md
浏览文件 @
b5eca1cc
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录