完成tflite_micro库目录结构,完成496TF移植部分文档
This commit is contained in:
@@ -60,16 +60,16 @@
|
||||
|
||||
以下是整个例程的目录规划:
|
||||
|
||||
| 一级目录 | 二级目录 | 三级目录 | 说明 |
|
||||
| :-------: | :--------------------------: | :------: | :----------------------------------------------------------: |
|
||||
| arch | arm | | TencentOS tiny适配的IP核架构(含M核中断、调度、tick相关代码) |
|
||||
| board | NUCLEO_STM32L496ZG | | 移植目标芯片的工程文件 |
|
||||
| | | BSP | 板级支持包,外设驱动代码在Hardware目录 |
|
||||
| component | tflite_micro | | tflite_micro源码 |
|
||||
| examples | tflitemicro_person_detection | | 行人检测demo示例 |
|
||||
| kernel | core | | TencentOS tiny内核源码 |
|
||||
| | pm | | TencentOS tiny低功耗模块源码 |
|
||||
| osal | cmsis_os | | TencentOS tiny提供的cmsis os 适配 |
|
||||
| 一级目录 | 二级目录 | 三级目录 | 说明 |
|
||||
| :-------: | :--------------------------: | :----------: | :----------------------------------------------------------: |
|
||||
| arch | arm | | TencentOS tiny适配的IP核架构(含M核中断、调度、tick相关代码) |
|
||||
| board | NUCLEO_STM32L496ZG | | 移植目标芯片的工程文件 |
|
||||
| | | BSP | 板级支持包,外设驱动代码在Hardware目录 |
|
||||
| component | ai | tflite_micro | tflite_micro源码 |
|
||||
| examples | tflitemicro_person_detection | | 行人检测demo示例 |
|
||||
| kernel | core | | TencentOS tiny内核源码 |
|
||||
| | pm | | TencentOS tiny低功耗模块源码 |
|
||||
| osal | cmsis_os | | TencentOS tiny提供的cmsis os 适配 |
|
||||
|
||||
完成TencentOS tiny基础keil工程准备工作后,在这个keil工程的基础上继续添加外设驱动代码。
|
||||
|
||||
@@ -128,23 +128,59 @@ void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
|
||||
|
||||
## 三、Tensorflow Lite Micro移植
|
||||
|
||||
### 1. tflite_micro源码加入到keil工程
|
||||
### 1. tflite_micro组件加入到keil工程
|
||||
|
||||
由于NUCLEO-L496ZG芯片中的内核为ARM Cortex M4,所以本次我们可以直接使用ARM Cortex M4版本的tensorflow_lite_micro.lib库来简化tflite_micro搭建流程。
|
||||
|
||||
#### 1.1 在project中加入新的文件夹tensorflow:
|
||||
|
||||
<div align=center>
|
||||
<img src="./image/tflu_tensorflow文件夹增加的内容.png" width=80% />
|
||||
</div>
|
||||
|
||||
#### 1.2 添加本次与行人检测demo有关的源文件
|
||||
|
||||
<div align=center>
|
||||
<img src="./image/tflu_需要添加的文件.png" width=80% />
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
### 2. 解决编译错误
|
||||
其中,retarget.c的路径为:`TencentOS-tiny\components\ai\tflite_micro\KEIL\retarget.c`
|
||||
|
||||
tensorflow_lite_micro.lib的路径为:`TencentOS-tiny\components\ai\tflite_micro\ARM_CortexM4_lib\tensorflow_lite_micro.lib`
|
||||
|
||||
其余.cc文件均在当前目录下的`tflu_person_detection`文件夹中。
|
||||
|
||||
#### 1.3 关闭Keil的MicroLib库:
|
||||
|
||||
<div align=center>
|
||||
<img src="./image/tflu_取消Microlib.png" width=80% />
|
||||
</div>
|
||||
#### 1.4 添加tflite_micro需要的头文件:
|
||||
|
||||
<div align=center>
|
||||
<img src="./image/tflu_添加include.png" width=80% />
|
||||
</div>
|
||||
|
||||
注:最下方的路径为:
|
||||
|
||||
```
|
||||
TencentOS-tiny\components\ai\tflite_micro\ARM_CortexM4_lib\tensorflow\lite\micro\tools\make\downloads
|
||||
```
|
||||
|
||||
#### 1.5 调整优化等级和tflite_micro的交互信息输出串口:
|
||||
|
||||
<div align=center>
|
||||
<img src="./image/tflu_STM32496宏.png" width=80% />
|
||||
</div>
|
||||
|
||||
其中宏`NUCLEO_STM32L496ZG`是指定Nucleo STM32L496的hlpuart1为系统printf函数的输出串口,具体定义在Nucleo STM32L496的BSP文件夹中的`mcu_init.c`中。
|
||||
|
||||
|
||||
### 2. 编写Person_Detection 任务函数
|
||||
|
||||
### 3. 测试行人检测模型
|
||||
|
||||
|
||||
|
||||
### 4. 编写Person_Detection 任务函数
|
||||
|
||||
|
||||
|
||||
#### 4.1 图像预处理
|
||||
#### 2.1 图像预处理
|
||||
|
||||
<div align=center>
|
||||
<img src="./image/RGB565.jpg" width=50% />
|
||||
@@ -174,9 +210,7 @@ void input_convert(uint16_t* camera_buffer , uint8_t* model_buffer)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
#### 4.2 行人检测线程任务函数
|
||||
#### 3.2 行人检测线程任务函数
|
||||
|
||||
```c
|
||||
void task1(void *arg)
|
||||
|
@@ -12,7 +12,7 @@
|
||||
<lExt>*.lib</lExt>
|
||||
<tExt>*.txt; *.h; *.inc</tExt>
|
||||
<pExt>*.plm</pExt>
|
||||
<CppX>*.cpp</CppX>
|
||||
<CppX>*.cpp;*.cc</CppX>
|
||||
<nMigrate>0</nMigrate>
|
||||
</Extensions>
|
||||
|
||||
@@ -1051,7 +1051,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>hal</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
@@ -1119,7 +1119,7 @@
|
||||
|
||||
<Group>
|
||||
<GroupName>examples</GroupName>
|
||||
<tvExp>1</tvExp>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<cbSel>0</cbSel>
|
||||
<RteFlg>0</RteFlg>
|
||||
@@ -1146,24 +1146,84 @@
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>71</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<FileType>8</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\..\components\tflite_micro\KEIL\regarget.c</PathWithFileName>
|
||||
<FilenameWithoutPath>regarget.c</FilenameWithoutPath>
|
||||
<PathWithFileName>.\tflu_person_detection\person_detect_model_data.cc</PathWithFileName>
|
||||
<FilenameWithoutPath>person_detect_model_data.cc</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>72</FileNumber>
|
||||
<FileType>8</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\tflu_person_detection\model_settings.cc</PathWithFileName>
|
||||
<FilenameWithoutPath>model_settings.cc</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>73</FileNumber>
|
||||
<FileType>8</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\tflu_person_detection\main_functions.cc</PathWithFileName>
|
||||
<FilenameWithoutPath>main_functions.cc</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>74</FileNumber>
|
||||
<FileType>8</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\tflu_person_detection\image_provider.cc</PathWithFileName>
|
||||
<FilenameWithoutPath>image_provider.cc</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>75</FileNumber>
|
||||
<FileType>8</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>.\tflu_person_detection\detection_responder.cc</PathWithFileName>
|
||||
<FilenameWithoutPath>detection_responder.cc</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>76</FileNumber>
|
||||
<FileType>1</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\..\components\ai\tflite_micro\KEIL\retarget.c</PathWithFileName>
|
||||
<FilenameWithoutPath>retarget.c</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
<File>
|
||||
<GroupNumber>10</GroupNumber>
|
||||
<FileNumber>77</FileNumber>
|
||||
<FileType>4</FileType>
|
||||
<tvExp>0</tvExp>
|
||||
<tvExpOptDlg>0</tvExpOptDlg>
|
||||
<bDave2>0</bDave2>
|
||||
<PathWithFileName>..\..\..\..\components\tflite_micro\ARM_CortexM4_lib\tflm_person_detection.lib</PathWithFileName>
|
||||
<FilenameWithoutPath>tflm_person_detection.lib</FilenameWithoutPath>
|
||||
<PathWithFileName>..\..\..\..\components\ai\tflite_micro\ARM_CortexM4_lib\tensorflow_lite_micro_M4.lib</PathWithFileName>
|
||||
<FilenameWithoutPath>tensorflow_lite_micro_M4.lib</FilenameWithoutPath>
|
||||
<RteFlg>0</RteFlg>
|
||||
<bShared>0</bShared>
|
||||
</File>
|
||||
|
@@ -16,8 +16,8 @@
|
||||
<TargetCommonOption>
|
||||
<Device>STM32L496ZGTx</Device>
|
||||
<Vendor>STMicroelectronics</Vendor>
|
||||
<PackID>Keil.STM32L4xx_DFP.2.4.0</PackID>
|
||||
<PackURL>http://www.keil.com/pack/</PackURL>
|
||||
<PackID>Keil.STM32L4xx_DFP.2.5.0</PackID>
|
||||
<PackURL>https://www.keil.com/pack/</PackURL>
|
||||
<Cpu>IRAM(0x20000000-0x2004FFFF) IROM(0x8000000-0x80FFFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4")</Cpu>
|
||||
<FlashUtilSpec></FlashUtilSpec>
|
||||
<StartupFile></StartupFile>
|
||||
@@ -313,7 +313,7 @@
|
||||
</ArmAdsMisc>
|
||||
<Cads>
|
||||
<interw>1</interw>
|
||||
<Optim>7</Optim>
|
||||
<Optim>4</Optim>
|
||||
<oTime>0</oTime>
|
||||
<SplitLS>0</SplitLS>
|
||||
<OneElfS>1</OneElfS>
|
||||
@@ -339,7 +339,7 @@
|
||||
<MiscControls></MiscControls>
|
||||
<Define>USE_HAL_DRIVER,STM32L496xx,NUCLEO_STM32L496ZG</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\..\..\kernel\core\include;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\examples\hello_world;..\..\TOS_CONFIG;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\BSP\Hardware\Inc;..\..\..\..\components\tflite_micro\ARM_CortexM4_lib;..\..\..\..\components\tflite_micro\ARM_CortexM4_lib\third_party\flatbuffers\include;..\..\..\..\components\tflite_micro\ARM_CortexM4_lib\third_party\gemmlowp;..\..\..\..\components\tflite_micro\ARM_CortexM4_lib\third_party\kissfft;..\..\..\..\components\tflite_micro\ARM_CortexM4_lib\third_party\ruy;..\..\..\..\components\tflite_micro\ARM_CortexM4_lib\tensorflow\lite\micro\tools\make\downloads</IncludePath>
|
||||
<IncludePath>..\..\BSP\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc;..\..\..\..\platform\vendor_bsp\st\STM32L4xx_HAL_Driver\Inc\Legacy;..\..\..\..\platform\vendor_bsp\st\CMSIS\Device\ST\STM32L4xx\Include;..\..\..\..\platform\vendor_bsp\st\CMSIS\Include;..\..\..\..\arch\arm\arm-v7m\common\include;..\..\..\..\arch\arm\arm-v7m\cortex-m4\armcc;..\..\..\..\kernel\core\include;..\..\..\..\kernel\pm\include;..\..\..\..\osal\cmsis_os;..\..\..\..\examples\hello_world;..\..\TOS_CONFIG;..\..\..\..\net\at\include;..\..\..\..\kernel\hal\include;..\..\BSP\Hardware\Inc;..\..\..\..\components\ai\tflite_micro\ARM_CortexM4_lib;..\..\..\..\components\ai\tflite_micro\ARM_CortexM4_lib\third_party\flatbuffers\include;..\..\..\..\components\ai\tflite_micro\ARM_CortexM4_lib\third_party\gemmlowp;..\..\..\..\components\ai\tflite_micro\ARM_CortexM4_lib\third_party\kissfft;..\..\..\..\components\ai\tflite_micro\ARM_CortexM4_lib\third_party\ruy;..\..\..\..\components\ai\tflite_micro\ARM_CortexM4_lib\tensorflow\lite\micro\tools\make\downloads</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
@@ -779,14 +779,39 @@
|
||||
<GroupName>tensorflow</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>regarget.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\components\tflite_micro\KEIL\regarget.c</FilePath>
|
||||
<FileName>person_detect_model_data.cc</FileName>
|
||||
<FileType>8</FileType>
|
||||
<FilePath>.\tflu_person_detection\person_detect_model_data.cc</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>tflm_person_detection.lib</FileName>
|
||||
<FileName>model_settings.cc</FileName>
|
||||
<FileType>8</FileType>
|
||||
<FilePath>.\tflu_person_detection\model_settings.cc</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>main_functions.cc</FileName>
|
||||
<FileType>8</FileType>
|
||||
<FilePath>.\tflu_person_detection\main_functions.cc</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>image_provider.cc</FileName>
|
||||
<FileType>8</FileType>
|
||||
<FilePath>.\tflu_person_detection\image_provider.cc</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>detection_responder.cc</FileName>
|
||||
<FileType>8</FileType>
|
||||
<FilePath>.\tflu_person_detection\detection_responder.cc</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>retarget.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\..\..\components\ai\tflite_micro\KEIL\retarget.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>tensorflow_lite_micro_M4.lib</FileName>
|
||||
<FileType>4</FileType>
|
||||
<FilePath>..\..\..\..\components\tflite_micro\ARM_CortexM4_lib\tflm_person_detection.lib</FilePath>
|
||||
<FilePath>..\..\..\..\components\ai\tflite_micro\ARM_CortexM4_lib\tensorflow_lite_micro_M4.lib</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 535 KiB |
Binary file not shown.
After Width: | Height: | Size: 139 KiB |
Binary file not shown.
After Width: | Height: | Size: 67 KiB |
Binary file not shown.
After Width: | Height: | Size: 113 KiB |
Binary file not shown.
After Width: | Height: | Size: 170 KiB |
Binary file not shown.
After Width: | Height: | Size: 82 KiB |
@@ -0,0 +1,25 @@
|
||||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include "tensorflow/lite/micro/examples/person_detection_experimental/detection_responder.h"
|
||||
|
||||
// This dummy implementation writes person and no person scores to the error
|
||||
// console. Real applications will want to take some custom action instead, and
|
||||
// should implement their own versions of this function.
|
||||
void RespondToDetection(tflite::ErrorReporter* error_reporter,
|
||||
int8_t person_score, int8_t no_person_score) {
|
||||
TF_LITE_REPORT_ERROR(error_reporter, "person score:%d no person score %d",
|
||||
person_score, no_person_score);
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include "tensorflow/lite/micro/examples/person_detection_experimental/image_provider.h"
|
||||
#include "tensorflow/lite/micro/examples/person_detection_experimental/model_settings.h"
|
||||
|
||||
TfLiteStatus GetImage(tflite::ErrorReporter* error_reporter, int image_width,
|
||||
int image_height, int channels, int8_t* image_data,
|
||||
uint8_t * hardware_input) {
|
||||
for (int i = 0; i < image_width * image_height * channels; ++i) {
|
||||
image_data[i] = hardware_input[i];
|
||||
}
|
||||
return kTfLiteOk;
|
||||
}
|
@@ -0,0 +1,119 @@
|
||||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include "tensorflow/lite/micro/examples/person_detection_experimental/main_functions.h"
|
||||
|
||||
#include "tensorflow/lite/micro/examples/person_detection_experimental/detection_responder.h"
|
||||
#include "tensorflow/lite/micro/examples/person_detection_experimental/image_provider.h"
|
||||
#include "tensorflow/lite/micro/examples/person_detection_experimental/model_settings.h"
|
||||
#include "tensorflow/lite/micro/examples/person_detection_experimental/person_detect_model_data.h"
|
||||
#include "tensorflow/lite/micro/micro_error_reporter.h"
|
||||
#include "tensorflow/lite/micro/micro_interpreter.h"
|
||||
#include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
|
||||
#include "tensorflow/lite/schema/schema_generated.h"
|
||||
#include "tensorflow/lite/version.h"
|
||||
|
||||
// Globals, used for compatibility with Arduino-style sketches.
|
||||
namespace {
|
||||
tflite::ErrorReporter* error_reporter = nullptr;
|
||||
const tflite::Model* model = nullptr;
|
||||
tflite::MicroInterpreter* interpreter = nullptr;
|
||||
TfLiteTensor* input = nullptr;
|
||||
|
||||
// In order to use optimized tensorflow lite kernels, a signed int8_t quantized
|
||||
// model is preferred over the legacy unsigned model format. This means that
|
||||
// throughout this project, input images must be converted from unisgned to
|
||||
// signed format. The easiest and quickest way to convert from unsigned to
|
||||
// signed 8-bit integers is to subtract 128 from the unsigned value to get a
|
||||
// signed value.
|
||||
|
||||
// An area of memory to use for input, output, and intermediate arrays.
|
||||
constexpr int kTensorArenaSize = 115 * 1024;
|
||||
static uint8_t tensor_arena[kTensorArenaSize];
|
||||
} // namespace
|
||||
|
||||
// The name of this function is important for Arduino compatibility.
|
||||
void person_detect_init() {
|
||||
// Set up logging. Google style is to avoid globals or statics because of
|
||||
// lifetime uncertainty, but since this has a trivial destructor it's okay.
|
||||
// NOLINTNEXTLINE(runtime-global-variables)
|
||||
static tflite::MicroErrorReporter micro_error_reporter;
|
||||
error_reporter = µ_error_reporter;
|
||||
|
||||
// Map the model into a usable data structure. This doesn't involve any
|
||||
// copying or parsing, it's a very lightweight operation.
|
||||
model = tflite::GetModel(g_person_detect_model_data);
|
||||
if (model->version() != TFLITE_SCHEMA_VERSION) {
|
||||
TF_LITE_REPORT_ERROR(error_reporter,
|
||||
"Model provided is schema version %d not equal "
|
||||
"to supported version %d.",
|
||||
model->version(), TFLITE_SCHEMA_VERSION);
|
||||
return;
|
||||
}
|
||||
|
||||
// Pull in only the operation implementations we need.
|
||||
// This relies on a complete list of all the ops needed by this graph.
|
||||
// An easier approach is to just use the AllOpsResolver, but this will
|
||||
// incur some penalty in code space for op implementations that are not
|
||||
// needed by this graph.
|
||||
//
|
||||
// tflite::AllOpsResolver resolver;
|
||||
// NOLINTNEXTLINE(runtime-global-variables)
|
||||
static tflite::MicroMutableOpResolver<5> micro_op_resolver;
|
||||
micro_op_resolver.AddAveragePool2D();
|
||||
micro_op_resolver.AddConv2D();
|
||||
micro_op_resolver.AddDepthwiseConv2D();
|
||||
micro_op_resolver.AddReshape();
|
||||
micro_op_resolver.AddSoftmax();
|
||||
|
||||
// Build an interpreter to run the model with.
|
||||
// NOLINTNEXTLINE(runtime-global-variables)
|
||||
static tflite::MicroInterpreter static_interpreter(
|
||||
model, micro_op_resolver, tensor_arena, kTensorArenaSize, error_reporter);
|
||||
interpreter = &static_interpreter;
|
||||
|
||||
// Allocate memory from the tensor_arena for the model's tensors.
|
||||
TfLiteStatus allocate_status = interpreter->AllocateTensors();
|
||||
if (allocate_status != kTfLiteOk) {
|
||||
TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get information about the memory area to use for the model's input.
|
||||
input = interpreter->input(0);
|
||||
}
|
||||
|
||||
// The name of this function is important for Arduino compatibility.
|
||||
int person_detect(uint8_t * hardware_input) {
|
||||
// Get image from provider.
|
||||
if (kTfLiteOk != GetImage(error_reporter, kNumCols, kNumRows, kNumChannels,
|
||||
input->data.int8, hardware_input)) {
|
||||
TF_LITE_REPORT_ERROR(error_reporter, "Image capture failed.");
|
||||
}
|
||||
|
||||
// Run the model on this input and make sure it succeeds.
|
||||
if (kTfLiteOk != interpreter->Invoke()) {
|
||||
TF_LITE_REPORT_ERROR(error_reporter, "Invoke failed.");
|
||||
}
|
||||
|
||||
TfLiteTensor* output = interpreter->output(0);
|
||||
|
||||
// Process the inference results.
|
||||
int8_t person_score = output->data.uint8[kPersonIndex];
|
||||
int8_t no_person_score = output->data.uint8[kNotAPersonIndex];
|
||||
RespondToDetection(error_reporter, person_score, no_person_score);
|
||||
if(person_score >= no_person_score + 50) return 1;
|
||||
else return 0;
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
==============================================================================*/
|
||||
|
||||
#include "tensorflow/lite/micro/examples/person_detection_experimental/model_settings.h"
|
||||
|
||||
const char* kCategoryLabels[kCategoryCount] = {
|
||||
"notperson",
|
||||
"person",
|
||||
};
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user