diff --git a/board/NUCLEO_STM32L496ZG/BSP/Inc/mcu_init.h b/board/NUCLEO_STM32L496ZG/BSP/Inc/mcu_init.h
index 0623a76cfdf080eca29cfcabecdd811cc4559308..9152fc91e0c52526314f5ee30eb6206f967a09fe 100644
--- a/board/NUCLEO_STM32L496ZG/BSP/Inc/mcu_init.h
+++ b/board/NUCLEO_STM32L496ZG/BSP/Inc/mcu_init.h
@@ -13,8 +13,6 @@
#include "i2c.h"
#include "spi.h"
#include "tim.h"
-#include "ov2640.h"
-#include "lcd_2inch4.h"
#include "tos_k.h"
void board_init(void);
void SystemClock_Config(void);
diff --git a/board/NUCLEO_STM32L496ZG/BSP/Src/main.c b/board/NUCLEO_STM32L496ZG/BSP/Src/main.c
index 6eb346ed15adbfe279e0b13facc9001e05224387..14ff70d0c639273c2009577bd0ee47f2123aa29a 100644
--- a/board/NUCLEO_STM32L496ZG/BSP/Src/main.c
+++ b/board/NUCLEO_STM32L496ZG/BSP/Src/main.c
@@ -18,7 +18,6 @@ int main(void)
{
board_init();
printf("Welcome to TencentOS tiny\r\n");
- person_detect_init();
osKernelInitialize(); // TOS Tiny kernel initialize
osThreadCreate(osThread(application_entry), NULL); // Create TOS Tiny task
osKernelStart(); // Start TOS Tiny
diff --git a/board/NUCLEO_STM32L496ZG/BSP/Src/mcu_init.c b/board/NUCLEO_STM32L496ZG/BSP/Src/mcu_init.c
index 003382852015b6804581ed8ede06691bf83e4a83..9ce35a97dc592d644d7aada5cacc2918c95e1ec1 100644
--- a/board/NUCLEO_STM32L496ZG/BSP/Src/mcu_init.c
+++ b/board/NUCLEO_STM32L496ZG/BSP/Src/mcu_init.c
@@ -1,12 +1,9 @@
#include "mcu_init.h"
-uint16_t camera_buffer[OV2640_PIXEL_WIDTH*OV2640_PIXEL_HEIGHT];
uint8_t frame_flag = 0;
-uint8_t tensor_flag = 0;
extern DCMI_HandleTypeDef hdcmi;
-
int fputc(int ch, FILE *f)
{
if (ch == '\n') {
@@ -42,18 +39,6 @@ void board_init(void)
MX_I2C1_Init();
MX_SPI1_Init();
MX_TIM4_Init();
-
- LCD_2IN4_Init();
- OV2640_Init();
- OV2640_RGB565_Mode();
- OV2640_OutSize_Set(OV2640_PIXEL_WIDTH,OV2640_PIXEL_HEIGHT);
-
- __HAL_DCMI_DISABLE_IT(&hdcmi, DCMI_IT_LINE | DCMI_IT_VSYNC);
- if (HAL_DCMI_Start_DMA(&hdcmi, DCMI_MODE_CONTINUOUS, (uint32_t)camera_buffer , (OV2640_PIXEL_WIDTH*OV2640_PIXEL_HEIGHT)/2))
- {
- Error_Handler();
- }
- //setup(); //tensorflow init
}
/**
diff --git "a/board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TFlite_Micro_Demo\347\247\273\346\244\215\345\217\202\350\200\203\346\214\207\345\215\227\357\274\210Keil\347\211\210\357\274\211.md" "b/board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TFlite_Micro_Demo\347\247\273\346\244\215\345\217\202\350\200\203\346\214\207\345\215\227\357\274\210Keil\347\211\210\357\274\211.md"
index f15646c87699d87123bceb59da83bb886f551bca..5049e6e50dcd65e91968f2aec5a90b0e43c08d9f 100644
--- "a/board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TFlite_Micro_Demo\347\247\273\346\244\215\345\217\202\350\200\203\346\214\207\345\215\227\357\274\210Keil\347\211\210\357\274\211.md"
+++ "b/board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TFlite_Micro_Demo\347\247\273\346\244\215\345\217\202\350\200\203\346\214\207\345\215\227\357\274\210Keil\347\211\210\357\274\211.md"
@@ -1,330 +1,329 @@
-# TensorFlow Lite Micro移植参考指南(Keil版)
-
-**作者:**
-
-Github: [Derekduke](https://github.com/Derekduke) E-mail: dkeji627@gmail.com
-
-Github: [QingChuanWS](https://github.com/QingChuanWS) E-mail: bingshan45@163.com
-
-Github: [yangqings](https://github.com/yangqings) E-mail: yangqingsheng12@outlook.com
-
-## 概述
-
-本教程是基于STM32 NUCLEO-L496ZG(Cortex-M4, 80Mhz)开发板,在运行TencentOS tiny的基础上,使用Tensorflow Lite Micro框架和CMSIS-NN库(算子加速),在STM32L496ZG上实现了**行人检测模型**的推理。
-
-关于Tensorflow Lite Micro组件的详细介绍可以参考`TencentOS-tiny\components\ai\tflite_micro`目录下的TFlite_Micro_Component_User_Guide.md文档。
-
-本例程中,传入神经网络的RGB图像大小为 18kb(96*96 * 2byte),在STM32L496平台消耗的内存资源(经过优化后)如下:
-
-- SRAM:168 Kbyte
-- Flash:314 Kbyte
-
-理论上满足以上内存要求的STM32 Cortex-M系列MCU可以参考本指南进行移植。
-
-## 一、移植前的准备
-
-#### 1. 准备目标硬件(开发板/传感器/模组)
-
-需要准备如下硬件:
-
-- 开发板:NUCLEO-L496ZG,MCU为STM32L496ZG;
-- Camera:获取RGB图像,本例程使用OV2640摄像头;
-- LCD:显示RGB图像,本例程使用2.4寸LCD(SPI通信);
-
-硬件实物图如下:
-
-
-
-
-
-#### 2.准备TencentOS tiny基础keil工程代码
-
-- 首先,参考TencentOS tiny基于keil的移植教程进行移植:
- https://github.com/Tencent/TencentOS-tiny/blob/master/doc/10.Porting_Manual_for_KEIL.md
-- 为了方便初始化MCU的外设,后续要继续使用STM32CubeMX软件,请确保安装了该软件;
-
-- 移植成功后,工程可以进行线程任务切换,通过串口打印"hello world",基础keil工程代码准备完毕。
-
-#### 3. 获取Tensorflow Lite Micro
-
-有三种方式获取tflite_micro:
-
-1. 从TencentOS tiny 代码仓库 `components\ai\tflite_micro`目录获取;
-2. 以lib文件的形式使用tflite_micro组件,lib文件`TencentOS-tiny\components\ai\tflite_micro`的ARM_CortexM4_lib、ARM_CortexM7_lib和ARM_CortexM55_lib文件夹;
-3. 从Tensorflow代码仓库获取,TFlite_Micro的源码已经开源,github仓库地址为:https://github.com/tensorflow/tensorflow ,可根据google TFLite Micro官方教程获得Tensorflow Lite Micro的全部源码。
-
-如果没有tflite_micro开发经验,建议以**第一种**或者**第二种**方式获取tflite_micro,希望自行获取最新源码,或者编译lib文件,请参考`TencentOS-tiny\components\tflite_micro`目录的TFlite_Micro_Component_User_Guide.md文档,本指南将直接使用TencentOS tiny 代码仓库内的tflite_micro组件。
-
-## 二、BSP准备
-
-### 1. 工程目录规划
-
-以下是整个例程的目录规划:
-
-| 一级目录 | 二级目录 | 三级目录 | 说明 |
-| :-------: | :--------------------------: | :-------------------: | :----------------------------------------------------------: |
-| arch | arm | | TencentOS tiny适配的IP核架构(含M核中断、调度、tick相关代码) |
-| board | NUCLEO_STM32L496ZG | | 移植目标芯片的工程文件 |
-| | | BSP | 板级支持包,外设驱动代码在Hardware目录 |
-| component | ai | tflite_micro | tflite_micro源码及有关库文件 |
-| examples | tflitemicro_person_detection | | 行人检测demo示例 |
-| | | tflu_person_detection | 行人检测实例代码 |
-| kernel | core | | TencentOS tiny内核源码 |
-| | pm | | TencentOS tiny低功耗模块源码 |
-| osal | cmsis_os | | TencentOS tiny提供的cmsis os 适配 |
-
-完成TencentOS tiny基础keil工程准备工作后,在这个keil工程的基础上继续添加外设驱动代码。
-
-### 2. LCD驱动
-
-本例程选用一款2.4寸LCD屏幕,分辨率为 240*320, SPI 接口通信,内部控制芯片为IL9341。
-
-开发者也可以使用其他LCD,自行完成LCD的驱动代码移植,方便调试摄像头,以及查看图像是否正常。
-
-#### 2.1 SPI初始化
-
-进入`TencentOS-tiny\board\NUCLEO_STM32L496ZG\BSP`目录,打开TencentOS_tiny.ioc工程,使用STM32CubeMX初始化MCU外设。
-
-
-
-
-#### 2.2 打开keil的Manage Project Items
-
-
-
-
-
-#### 2.3 在project中加入新的文件夹hal
-
-
-
-
-
-
-#### 2.3 添加驱动代码
-
-添加`lcd_2inch4.c`和`lcd_config.c`,
-
-
-
-
-
-
-
-添加头文件`lcd_2inch4.h`和`lcd_config.h`路径
-
-
-
-
-
-
-
-
-
-
-外设驱动的头文件.h文件都在`TencentOS-tiny\board\NUCLEO_STM32L496ZG\BSP\Hardware\Inc`路径下。
-
-### 3. 摄像头驱动
-
-#### 3.1 外设初始化
-
-进入`TencentOS-tiny\board\NUCLEO_STM32L496ZG\BSP`目录,打开TencentOS_tiny.ioc工程,初始化DCMI外设,打开DCMI全局中断,并打开DMA通道,DMA的Direction设置为Peripheral To Memory。
-
-
-
-
-
-
-
-
-
-
-
-#### 3.2 添加驱动代码
-
-
-
-
-
-**在mcu_init函数重写DCMI帧中断回调函数:**
-
-值得注意的是,代码需要写在CubeMx生成的注释语句内,当使用CubeMX重新配置外设并生成代码时,所添加的代码才不会被覆盖掉,如下所示,代码添加在/* USER CODE BEGIN 4 */ 和 /* USER CODE END 4 */注释语句之间:
-
-```C
-/* USER CODE BEGIN 4 */
-void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
-{
- if(hdcmi->State == 2 && frame_flag != 1){
- frame_flag = 1;
- }
-}
-/* USER CODE END 4 */
-```
-
-### 4. LCD显示摄像头图像
-
-本例程的任务函数在
-
-`TencentOS-tiny\examples\tflitemicro_person_detection\tflitemicro_person_detection.c`
-
-```c
-void task1(void *arg)
-{
- while (1) {
- if(frame_flag == 1){
-
- if(HAL_DCMI_Stop(&hdcmi))Error_Handler(); //stop DCMI
- LCD_2IN4_Display(camera_buffer,OV2640_PIXEL_WIDTH,OV2640_PIXEL_HEIGHT);
- //display
- frame_flag = 0;
- if(HAL_DCMI_Start_DMA(&hdcmi,DCMI_MODE_CONTINUOUS,\ //restart DCMI
- (uint32_t)camera_buffer ,\
- (OV2640_PIXEL_WIDTH*OV2640_PIXEL_HEIGHT)/2))
- Error_Handler();
- osDelay(50);
- }
-}
-```
-
-经过以上步骤,如果能顺利地驱动摄像头,并在LCD实时显示图像,BSP就准备完毕了,如果使用的是不同的LCD或者Camera,请根据实际情况进行外设初始化和驱动的移植。
-
-## 三、Tensorflow Lite Micro移植
-
-### 1. tflite_micro组件加入到keil工程
-
-由于NUCLEO-L496ZG芯片中的内核为ARM Cortex M4,所以本次我们可以直接使用ARM Cortex M4版本的tensorflow_lite_micro.lib库来简化tflite_micro搭建流程。
-
-#### 1.1 在project中加入新的文件夹tensorflow
-
-
-
-
-
-#### 1.2 添加本次与行人检测demo有关的源文件
-
-
-
-
-
-
-
-其中,retarget.c的路径为:`TencentOS-tiny\components\ai\tflite_micro\KEIL\retarget.c`
-
-tensorflow_lite_micro.lib的路径为:`TencentOS-stiny\components\ai\tflite_micro\ARM_CortexM4_lib\tensorflow_lite_micro.lib`
-
-其余.cc文件和.h均在`examples\tflu_person_detection\tflu_person_detection`文件夹中。
-
-#### 1.3 关闭Keil的MicroLib库
-
-
-
-
-
-#### 1.4 添加tflite_micro需要的头文件
-
-
-
-
-
-注:最下方的路径为:
-
-```
-TencentOS-tiny\components\ai\tflite_micro\ARM_CortexM4_lib\tensorflow\lite\micro\tools\make\downloads
-```
-
-#### 1.5 调整优化等级和tflite_micro的交互信息输出串口:
-
-
-
-
-
-其中宏`NUCLEO_STM32L496ZG`是指定Nucleo STM32L496的hlpuart1为系统printf函数的输出串口,具体定义在Nucleo STM32L496的BSP文件夹中的`mcu_init.c`中。
-
-### 2. 编写Person_Detection 任务函数
-
-本例程的任务函数在
-
-`TencentOS-tiny\examples\tflitemicro_person_detection\tflitemicro_person_detection.c`
-
-#### 2.1 图像预处理
-
-
-
-
-
-在本例程中,模型要求输入神经网络的图像为灰度图,为完成摄像头获取的RGB彩图到模型输入需要的灰度图转换,需从输入的RGB565像素格式中解析出R、G、B三通道的值,再根据心理学公式计算出单个像素点的灰度,具体代码如下:
-
-```c
-uint8_t rgb565_to_gray(uint16_t bg_color)
-{
- uint8_t bg_r = 0;
- uint8_t bg_g = 0;
- uint8_t bg_b = 0;
- bg_r = ((bg_color>>11)&0xff)<<3;
- bg_g = ((bg_color>>5)&0x3f)<<2;
- bg_b = (bg_color&0x1f)<<2;
- uint8_t gray = (bg_r*299 + bg_g*587 + bg_b*114 + 500) / 1000;
- return gray;
-}
-
-void input_convert(uint16_t* camera_buffer , uint8_t* model_buffer)
-{
- for(int i=0 ; i
-
-
-
-当摄像头对准行人时,输出如下:
-
-
-
-
-
-执行一帧图像推理,耗时约633 ms。
-
-更多关于tflite_micro的介绍,请参考[tensorflow](https://tensorflow.google.cn/lite/microcontrollers?hl=zh_cn)官网以及`TencentOS-tiny\components\tflite_micro`目录的TFlite_Micro_Component_User_Guide.md
-
+# TensorFlow Lite Micro移植参考指南(Keil版)
+
+**作者:**
+
+Github ID: [Derekduke](https://github.com/Derekduke) E-mail: dkeji627@gmail.com
+
+Github ID: [QingChuanWS](https://github.com/QingChuanWS) E-mail: bingshan45@163.com
+
+Github ID: [yangqings](https://github.com/yangqings) E-mail: yangqingsheng12@outlook.com
+
+## 概述
+
+本教程是基于STM32 NUCLEO-L496ZG(Cortex-M4, 80Mhz)开发板,在运行TencentOS tiny的基础上,使用Tensorflow Lite Micro框架和CMSIS-NN库(算子加速),在STM32L496ZG上实现了**行人检测模型**的推理。
+
+关于Tensorflow Lite Micro组件的详细介绍可以参考`TencentOS-tiny\components\ai\tflite_micro`目录下的TFlite_Micro_Component_User_Guide.md文档。
+
+本例程中,传入神经网络的RGB图像大小为 18kb(96*96 * 2byte),在STM32L496平台消耗的内存资源(经过优化后)如下:
+
+- SRAM:168 Kbyte
+- Flash:314 Kbyte
+
+理论上满足以上内存要求的STM32 Cortex-M系列MCU可以参考本指南进行移植。
+
+## 一、移植前的准备
+
+#### 1. 准备目标硬件(开发板/传感器/模组)
+
+需要准备如下硬件:
+
+- 开发板:NUCLEO-L496ZG,MCU为STM32L496ZG;
+- Camera:获取RGB图像,本例程使用OV2640摄像头;
+- LCD:显示RGB图像,本例程使用2.4寸LCD(SPI通信);
+
+硬件实物图如下:
+
+
+
+
+
+#### 2.准备TencentOS tiny基础keil工程代码
+
+- 首先,参考TencentOS tiny基于keil的移植教程进行移植:
+ https://github.com/Tencent/TencentOS-tiny/blob/master/doc/10.Porting_Manual_for_KEIL.md
+- 为了方便初始化MCU的外设,后续要继续使用STM32CubeMX软件,请确保安装了该软件;
+
+- 移植成功后,工程可以进行线程任务切换,通过串口打印"hello world",基础keil工程代码准备完毕。
+
+#### 3. 获取Tensorflow Lite Micro
+
+有三种方式获取tflite_micro:
+
+1. 从TencentOS tiny 代码仓库 `components\ai\tflite_micro`目录获取;
+2. 以lib文件的形式使用tflite_micro组件,lib文件`TencentOS-tiny\components\ai\tflite_micro`的ARM_CortexM4_lib、ARM_CortexM7_lib和ARM_CortexM55_lib文件夹
+3. 从Tensorflow代码仓库获取,TFlite_Micro的源码已经开源,github仓库地址为:https://github.com/tensorflow/tensorflow ,可根据google TFLite Micro官方教程获得Tensorflow Lite Micro的全部源码。
+
+如果没有tflite_micro开发经验,建议以**第一种**或者**第二种**方式获取tflite_micro,希望自行获取最新源码,或者编译lib文件,请参考`TencentOS-tiny\components\tflite_micro`目录的TFlite_Micro_Component_User_Guide.md文档,本指南将直接使用TencentOS tiny 代码仓库内的tflite_micro组件。
+
+## 二、BSP准备
+
+### 1. 工程目录规划
+
+以下是整个例程的目录规划:
+
+| 一级目录 | 二级目录 | 三级目录 | 说明 |
+| :-------: | :--------------------------: | :----------: | :----------------------------------------------------------: |
+| 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工程的基础上继续添加外设驱动代码。
+
+### 2. LCD驱动
+
+本例程选用一款2.4寸LCD屏幕,分辨率为 240*320, SPI 接口通信,内部控制芯片为IL9341。
+
+开发者也可以使用其他LCD,自行完成LCD的驱动代码移植,方便调试摄像头,以及查看图像是否正常。
+
+#### 2.1 SPI初始化
+
+进入`TencentOS-tiny\board\NUCLEO_STM32L496ZG\BSP`目录,打开TencentOS_tiny.ioc工程,使用STM32CubeMX初始化MCU外设。
+
+
+
+
+#### 2.2 打开keil的Manage Project Items
+
+
+
+
+
+#### 2.3 在project中加入新的文件夹hal
+
+
+
+
+
+
+#### 2.3 添加驱动代码
+
+添加`lcd_2inch4.c`和`lcd_config.c`,
+
+
+
+
+
+
+
+添加头文件`lcd_2inch4.h`和`lcd_config.h`路径
+
+
+
+
+
+
+
+
+
+
+外设驱动的头文件.h文件都在`TencentOS-tiny\board\NUCLEO_STM32L496ZG\BSP\Hardware\Inc`路径下。
+
+### 3. 摄像头驱动
+
+#### 3.1 外设初始化
+
+进入`TencentOS-tiny\board\NUCLEO_STM32L496ZG\BSP`目录,打开TencentOS_tiny.ioc工程,初始化DCMI外设,打开DCMI全局中断,并打开DMA通道,DMA的Direction设置为Peripheral To Memory。
+
+
+
+
+
+
+
+
+
+
+
+#### 3.2 添加驱动代码
+
+
+
+
+
+**在mcu_init函数重写DCMI帧中断回调函数:**
+
+值得注意的是,代码需要写在CubeMx生成的注释语句内,当使用CubeMX重新配置外设并生成代码时,所添加的代码才不会被覆盖掉,如下所示,代码添加在/* USER CODE BEGIN 4 */ 和 /* USER CODE END 4 */注释语句之间:
+
+```C
+/* USER CODE BEGIN 4 */
+void HAL_DCMI_FrameEventCallback(DCMI_HandleTypeDef *hdcmi)
+{
+ if(hdcmi->State == 2 && frame_flag != 1){
+ frame_flag = 1;
+ }
+}
+/* USER CODE END 4 */
+```
+
+### 4. LCD显示摄像头图像
+
+本例程的任务函数在
+
+`TencentOS-tiny\examples\tflitemicro_person_detection\tflitemicro_person_detection.c`
+
+```c
+void task1(void *arg)
+{
+ while (1) {
+ if(frame_flag == 1){
+
+ if(HAL_DCMI_Stop(&hdcmi))Error_Handler(); //stop DCMI
+ LCD_2IN4_Display(camera_buffer,OV2640_PIXEL_WIDTH,OV2640_PIXEL_HEIGHT);
+ //display
+ frame_flag = 0;
+ if(HAL_DCMI_Start_DMA(&hdcmi,DCMI_MODE_CONTINUOUS,\ //restart DCMI
+ (uint32_t)camera_buffer ,\
+ (OV2640_PIXEL_WIDTH*OV2640_PIXEL_HEIGHT)/2))
+ Error_Handler();
+ osDelay(50);
+ }
+}
+```
+
+经过以上步骤,如果能顺利地驱动摄像头,并在LCD实时显示图像,BSP就准备完毕了,如果使用的是不同的LCD或者Camera,请根据实际情况进行外设初始化和驱动的移植。
+
+## 三、Tensorflow Lite Micro移植
+
+### 1. tflite_micro组件加入到keil工程
+
+由于NUCLEO-L496ZG芯片中的内核为ARM Cortex M4,所以本次我们可以直接使用ARM Cortex M4版本的tensorflow_lite_micro.lib库来简化tflite_micro搭建流程。
+
+#### 1.1 在project中加入新的文件夹tensorflow
+
+
+
+
+
+#### 1.2 添加本次与行人检测demo有关的源文件
+
+
+
+
+
+
+
+其中,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库
+
+
+
+
+
+#### 1.4 添加tflite_micro需要的头文件
+
+
+
+
+
+注:最下方的路径为:
+
+```
+TencentOS-tiny\components\ai\tflite_micro\ARM_CortexM4_lib\tensorflow\lite\micro\tools\make\downloads
+```
+
+#### 1.5 调整优化等级和tflite_micro的交互信息输出串口:
+
+
+
+
+
+其中宏`NUCLEO_STM32L496ZG`是指定Nucleo STM32L496的hlpuart1为系统printf函数的输出串口,具体定义在Nucleo STM32L496的BSP文件夹中的`mcu_init.c`中。
+
+### 2. 编写Person_Detection 任务函数
+
+本例程的任务函数在
+
+`TencentOS-tiny\examples\tflitemicro_person_detection\tflitemicro_person_detection.c`目录下
+
+#### 2.1 图像预处理
+
+
+
+
+
+在本例程中,模型要求输入神经网络的图像为灰度图,为完成摄像头获取的RGB彩图到模型输入需要的灰度图转换,需从输入的RGB565像素格式中解析出R、G、B三通道的值,再根据心理学公式计算出单个像素点的灰度,具体代码如下:
+
+```c
+uint8_t rgb565_to_gray(uint16_t bg_color)
+{
+ uint8_t bg_r = 0;
+ uint8_t bg_g = 0;
+ uint8_t bg_b = 0;
+ bg_r = ((bg_color>>11)&0xff)<<3;
+ bg_g = ((bg_color>>5)&0x3f)<<2;
+ bg_b = (bg_color&0x1f)<<2;
+ uint8_t gray = (bg_r*299 + bg_g*587 + bg_b*114 + 500) / 1000;
+ return gray;
+}
+
+void input_convert(uint16_t* camera_buffer , uint8_t* model_buffer)
+{
+ for(int i=0 ; i
+
+
+
+当镜头对准行人时,输出如下:
+
+
+
+
+
+执行一帧图像推理,耗时约633 ms。
+
+更多关于tflite_micro的介绍,请参考[tensorflow](https://tensorflow.google.cn/lite/microcontrollers?hl=zh_cn)官网以及`TencentOS-tiny\components\tflite_micro`目录的TFlite_Micro_Component_User_Guide.md
+
diff --git a/board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TencentOS_tiny.uvoptx b/board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TencentOS_tiny.uvoptx
index d09e25cae252bc8f46acf59e5c1aee450f69b0b2..b49158a40f305eb7e30f05d16a151dd0b7363b15 100644
--- a/board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TencentOS_tiny.uvoptx
+++ b/board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TencentOS_tiny.uvoptx
@@ -12,7 +12,7 @@
*.lib
*.txt; *.h; *.inc
*.plm
- *.cpp
+ *.cpp;*.cc
0
diff --git a/board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TencentOS_tiny.uvprojx b/board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TencentOS_tiny.uvprojx
index 4e55bc3fd822ca965ab2700d4e05f454d9a8747f..3d896c08093998085a0c149aa81825af2bdbd655 100644
--- a/board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TencentOS_tiny.uvprojx
+++ b/board/NUCLEO_STM32L496ZG/KEIL/tflitemicro_person_detection/TencentOS_tiny.uvprojx
@@ -16,8 +16,8 @@
STM32L496ZGTx
STMicroelectronics
- Keil.STM32L4xx_DFP.2.4.0
- http://www.keil.com/pack/
+ Keil.STM32L4xx_DFP.2.5.0
+ https://www.keil.com/pack/
IRAM(0x20000000-0x2004FFFF) IROM(0x8000000-0x80FFFFF) CLOCK(8000000) FPU2 CPUTYPE("Cortex-M4")
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/LICENSE b/components/ai/tflite_micro/ARM_CortexM55_lib/LICENSE
deleted file mode 100644
index 40f8c347693afa4897252cbc76000beef1f52770..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/LICENSE
+++ /dev/null
@@ -1,203 +0,0 @@
-Copyright 2019 The TensorFlow Authors. All rights reserved.
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- 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.
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/core/public/version.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/core/public/version.h
deleted file mode 100644
index 431784a5a1a5afdc3c16abc5d2329164f565d704..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/core/public/version.h
+++ /dev/null
@@ -1,139 +0,0 @@
-/* Copyright 2015 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.
-==============================================================================*/
-
-#ifndef TENSORFLOW_CORE_PUBLIC_VERSION_H_
-#define TENSORFLOW_CORE_PUBLIC_VERSION_H_
-
-// TensorFlow uses semantic versioning, see http://semver.org/.
-
-// Also update tensorflow/tensorflow.bzl and
-// tensorflow/tools/pip_package/setup.py
-#define TF_MAJOR_VERSION 2
-#define TF_MINOR_VERSION 4
-#define TF_PATCH_VERSION 0
-
-// TF_VERSION_SUFFIX is non-empty for pre-releases (e.g. "-alpha", "-alpha.1",
-// "-beta", "-rc", "-rc.1")
-#define TF_VERSION_SUFFIX ""
-
-#define TF_STR_HELPER(x) #x
-#define TF_STR(x) TF_STR_HELPER(x)
-
-// e.g. "0.5.0" or "0.6.0-alpha".
-#define TF_VERSION_STRING \
- (TF_STR(TF_MAJOR_VERSION) "." TF_STR(TF_MINOR_VERSION) "." TF_STR( \
- TF_PATCH_VERSION) TF_VERSION_SUFFIX)
-
-// GraphDef compatibility versions (the versions field in graph.proto).
-//
-// Each graph has producer and min_consumer versions, and each
-// consumer has its own version and a min_producer. In addition, graphs can
-// mark specific consumer versions as bad (to prevent bugs from executing).
-// A consumer will execute a graph if the consumer's version is at least the
-// graph's min_consumer, the graph's producer version is at least the consumer's
-// min_producer, and the consumer version isn't specifically disallowed by the
-// graph.
-//
-// By default, newly created graphs have producer version TF_GRAPH_DEF_VERSION
-// min_consumer TF_GRAPH_DEF_MIN_CONSUMER, and no other bad consumer versions.
-//
-// Version history:
-//
-// 0. Graphs created before GraphDef versioning
-// 1. First real version (2dec2015)
-// 2. adjust_contrast only takes float, doesn't perform clamping (11dec2015)
-// 3. Remove TileGrad, since it was equivalent to reduce_sum (30dec2015)
-// 4. When support for this version is removed, we can safely make AttrValue
-// parsing more strict with respect to empty list values (see
-// 111635679, 7jan2016).
-// 5. Graphs are wholly-validated during Session::Create() (7jan2016).
-// 6. TensorFlow is scalar strict within Google (27jan2016).
-// 7. Remove TopK in favor of TopKV2 (5feb2016).
-// 8. Replace RandomCrop from C++ with pure Python (5feb2016).
-// 9. Deprecate batch_norm_with_global_normalization (16feb2016).
-// 10. Deprecate conv3d_backprop_{filter,input} (10jun2016).
-// 11. Deprecate {batch}_self_adjoint_eig (3aug2016).
-// 12. Graph consumers understand the node_def field of FunctionDef (22aug2016).
-// 13. Deprecate multiple batch linear algebra ops (9sep2016).
-// 14. Deprecate batch_matrix_* ops. (10sep2016).
-// 15. Deprecate batch_fft_* ops. (14sep2016).
-// 16. Deprecate tensor_array (v1) ops in favor of v2 (10nov2016).
-// 17. Deprecate inv (11nov2016).
-// 17. Expose reverse_v2 (10nov2016)
-// 18. Add VariableV2 (30nov2016)
-// 19. Deprecated ops created by models moved out of core SkipGram, NegTrain.
-// (08dec2016)
-// 20. Catch all version 1.0 changes to Python API generation. SplitV is now
-// used for tf.split, ReverseV2 is now used by tf.reverse, ConcatV2 is
-// now used by tf.concat. Graphs use flooring
-// division and mod semantics. TensorArrayV3. (12dec2016)
-// Also considered the version for when it is required for reduction
-// ops' indices to be scalar or vector, and not higher rank.
-// Some earlier graph def versions allowed this.
-// 21. Dropped FunctionDef.Node support, switched to node_def introduced
-// in version 12. (11jan2017)
-// 22. Placeholder now can specify and enforce scalar and partial
-// shapes, particularly when restoring a graph from GraphDef
-// produced at version 22 or later. (04/10/2016)
-// 23. Remove NonMaxSuppression in favor of NonMaxSuppressionV2.
-// 24. Deprecate lookup ops (v1) ops in favor of v2 (30may2017)
-// 25. Deprecate stack (v1) ops in favor of v2 (2017/6/15).
-// 25. Deprecate RandomPoisson (v1) ops in favor of v2 (2017/10/25).
-// 26. Add a bool 'stripped_default_attrs' to MetaInfoDef indicating
-// whether default-valued attrs have been stripped from the nodes in the
-// GraphDef. (7dec2017)
-// 27. Deprecate TensorArray ops v2 in favor of v3 and deprecated io_ops
-// deprecated in favor of V2 ops. (2018/01/23)
-// 28. Deprecate MatrixExponential op in favor of Python implementation.
-// (2018/08/21).
-// (2019/02/15). Added `control_ret` field to FunctionDef proto, and
-// `control_output` field to OpDef proto.
-// 29. Deprecate StatefulStandardNormal op in favor of StatefulStandardNormalV2.
-// (2019/03/25).
-// (2019/04/17). Added `arg_attr` field to FunctionDefProto.
-// 30. (2019/05/09) First date based GraphDef version. GraphDef
-// versions advance by 1 each day after this point.
-
-#define TF_GRAPH_DEF_VERSION_MIN_PRODUCER 0
-#define TF_GRAPH_DEF_VERSION_MIN_CONSUMER 0
-#define TF_GRAPH_DEF_VERSION 485 // Updated: 2020/8/6
-
-// Checkpoint compatibility versions (the versions field in SavedSliceMeta).
-//
-// The checkpoint versions have the same semantics as GraphDef versions, but the
-// numbering scheme is separate. We have no plans to ever deprecate checkpoint
-// versions, but it's good to have this in place in case we ever need to.
-//
-// Version history:
-//
-// 0. Checkpoints saved before checkpoint versioning.
-// 1. First real version (10feb2015).
-#define TF_CHECKPOINT_VERSION_MIN_PRODUCER 0
-#define TF_CHECKPOINT_VERSION_MIN_CONSUMER 0
-#define TF_CHECKPOINT_VERSION 1
-
-/// Version query functions (defined in generated version_info.cc)
-
-// Host compiler version (declared elsewhere to be __VERSION__)
-extern const char* tf_compiler_version();
-// The git commit designator when tensorflow was built
-// If no git repository, this will be "internal".
-extern const char* tf_git_version();
-// Value of the _GLIBCXX_USE_CXX11_ABI flag, or 0 if it's not set.
-extern int tf_cxx11_abi_flag();
-// Returns 1 if build is monolithic, or 0 otherwise.
-extern int tf_monolithic_build();
-
-#endif // TENSORFLOW_CORE_PUBLIC_VERSION_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/c/builtin_op_data.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/c/builtin_op_data.h
deleted file mode 100644
index e205f075b43dde345a0bce8a8b6bb564005657a5..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/c/builtin_op_data.h
+++ /dev/null
@@ -1,472 +0,0 @@
-/* Copyright 2017 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_
-#define TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_
-
-#include
-
-#include "tensorflow/lite/c/common.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-// TfLiteReshapeParams can't have dynamic data so we fix the maximum possible
-// number of dimensions.
-#define TFLITE_RESHAPE_PARAMS_MAX_DIMENSION_COUNT 8
-
-// TODO(aselle): Consider using "if this then that" for testing.
-
-// Useful placeholder to put in otherwise empty structs to avoid size warnings.
-typedef struct {
- char dummy;
-} EmptyStructPlaceholder;
-
-// IMPORTANT: All new members of structs must be added at the end to ensure
-// backwards compatibility.
-
-// Possible padding types (for convolutions)
-typedef enum {
- kTfLitePaddingUnknown = 0,
- kTfLitePaddingSame,
- kTfLitePaddingValid,
-} TfLitePadding;
-
-typedef enum {
- kTfLiteMirrorPaddingUnknown = 0,
- kTfLiteMirrorPaddingReflect,
- kTfLiteMirrorPaddingSymmetric,
-} TfLiteMirrorPaddingMode;
-
-// TODO(b/130259536): We should move this out of builtin_op_data.
-typedef struct {
- int width;
- int height;
- int width_offset;
- int height_offset;
-} TfLitePaddingValues;
-
-typedef struct {
- TfLiteMirrorPaddingMode mode;
-} TfLiteMirrorPaddingParams;
-
-// Possible fused activation functions.
-// TODO(aselle): rename to TfLiteActivation
-typedef enum {
- kTfLiteActNone = 0,
- kTfLiteActRelu,
- kTfLiteActReluN1To1, // min(max(-1, x), 1)
- kTfLiteActRelu1 = kTfLiteActReluN1To1, // kTfLiteActRelu1 will be deprecated.
- kTfLiteActRelu6, // min(max(0, x), 6)
- kTfLiteActTanh,
- kTfLiteActSignBit,
- kTfLiteActSigmoid,
-} TfLiteFusedActivation;
-
-typedef struct {
- // Parameters for CONV_2D version 1.
- TfLitePadding padding;
- int stride_width;
- int stride_height;
- TfLiteFusedActivation activation;
-
- // Parameters for CONV_2D version 2.
- // Note: Version 2 supports dilation values not equal to 1.
- int dilation_width_factor;
- int dilation_height_factor;
-} TfLiteConvParams;
-
-typedef struct {
- TfLitePadding padding;
- int stride_width;
- int stride_height;
- int filter_width;
- int filter_height;
- TfLiteFusedActivation activation;
- struct {
- TfLitePaddingValues padding;
- } computed;
-} TfLitePoolParams;
-
-typedef struct {
- // Parameters for DepthwiseConv version 1 or above.
- TfLitePadding padding;
- int stride_width;
- int stride_height;
- // `depth_multiplier` is redundant. It's used by CPU kernels in
- // TensorFlow 2.0 or below, but ignored in versions above.
- //
- // The information can be deduced from the shape of input and the shape of
- // weights. Since the TFLiteConverter toolchain doesn't support partially
- // specified shapes, relying on `depth_multiplier` stops us from supporting
- // graphs with dynamic shape tensors.
- //
- // Note: Some of the delegates (e.g. NNAPI, GPU) are still relying on this
- // field.
- int depth_multiplier;
- TfLiteFusedActivation activation;
- // Parameters for DepthwiseConv version 2 or above.
- int dilation_width_factor;
- int dilation_height_factor;
-} TfLiteDepthwiseConvParams;
-
-typedef struct {
- int rank;
- TfLiteFusedActivation activation;
-
- // Parameter for SVDF version 4.
- bool asymmetric_quantize_inputs;
-} TfLiteSVDFParams;
-
-typedef struct {
- TfLiteFusedActivation activation;
-
- // Parameter for RNN version 3.
- bool asymmetric_quantize_inputs;
-} TfLiteRNNParams;
-
-typedef struct {
- bool time_major;
- TfLiteFusedActivation activation;
-
- // Parameter for Sequence RNN version 3.
- bool asymmetric_quantize_inputs;
-} TfLiteSequenceRNNParams;
-
-typedef struct {
- bool time_major;
- TfLiteFusedActivation activation;
- bool merge_outputs;
-
- // Parameter for Bidirectional RNN verison 3.
- bool asymmetric_quantize_inputs;
-} TfLiteBidirectionalSequenceRNNParams;
-
-typedef enum {
- kTfLiteFullyConnectedWeightsFormatDefault = 0,
- kTfLiteFullyConnectedWeightsFormatShuffled4x16Int8 = 1,
-} TfLiteFullyConnectedWeightsFormat;
-
-typedef struct {
- // Parameters for FullyConnected version 1 or above.
- TfLiteFusedActivation activation;
-
- // Parameters for FullyConnected version 2 or above.
- TfLiteFullyConnectedWeightsFormat weights_format;
-
- // Parameters for FullyConnected version 5 or above.
- // If set to true, then the number of dimensions in the input and the output
- // tensors are the same. Furthermore, all but the last dimension of the input
- // and output shapes will be equal.
- bool keep_num_dims;
-
- // Parameters for FullyConnected version 7 or above.
- // If set to true and the weights are quantized, then non constant inputs
- // are quantized at evaluation time with asymmetric quantization.
- bool asymmetric_quantize_inputs;
-} TfLiteFullyConnectedParams;
-
-typedef enum {
- kTfLiteLshProjectionUnknown = 0,
- kTfLiteLshProjectionSparse = 1,
- kTfLiteLshProjectionDense = 2,
-} TfLiteLSHProjectionType;
-
-typedef struct {
- TfLiteLSHProjectionType type;
-} TfLiteLSHProjectionParams;
-
-typedef struct {
- float beta;
-} TfLiteSoftmaxParams;
-
-typedef struct {
- int axis;
- TfLiteFusedActivation activation;
-} TfLiteConcatenationParams;
-
-typedef struct {
- TfLiteFusedActivation activation;
- // Parameter added for the version 4.
- bool pot_scale_int16;
-} TfLiteAddParams;
-
-typedef struct {
- EmptyStructPlaceholder placeholder;
-} TfLiteSpaceToBatchNDParams;
-
-typedef struct {
- EmptyStructPlaceholder placeholder;
-} TfLiteBatchToSpaceNDParams;
-
-typedef struct {
- bool adj_x;
- bool adj_y;
-} TfLiteBatchMatMulParams;
-
-typedef struct {
- TfLiteFusedActivation activation;
-} TfLiteMulParams;
-
-typedef struct {
- TfLiteFusedActivation activation;
- // Parameter added for the version 5.
- bool pot_scale_int16;
-} TfLiteSubParams;
-
-typedef struct {
- TfLiteFusedActivation activation;
-} TfLiteDivParams;
-
-typedef struct {
- TfLiteFusedActivation activation;
-} TfLiteL2NormParams;
-
-typedef struct {
- int radius;
- float bias;
- float alpha;
- float beta;
-} TfLiteLocalResponseNormParams;
-
-typedef enum {
- kTfLiteLSTMFullKernel = 0,
- kTfLiteLSTMBasicKernel
-} TfLiteLSTMKernelType;
-
-typedef struct {
- // Parameters for LSTM version 1.
- TfLiteFusedActivation activation;
- float cell_clip;
- float proj_clip;
-
- // Parameters for LSTM version 2.
- // kTfLiteLSTMBasicKernel is only supported in version 2 or above.
- TfLiteLSTMKernelType kernel_type;
-
- // Parameters for LSTM version 4.
- bool asymmetric_quantize_inputs;
-} TfLiteLSTMParams;
-
-typedef struct {
- // Parameters needed for the underlying LSTM.
- TfLiteFusedActivation activation;
- float cell_clip;
- float proj_clip;
-
- // If set to true then the first dimension is time, otherwise batch.
- bool time_major;
-
- // Parameter for unidirectional sequence RNN version 3.
- bool asymmetric_quantize_inputs;
-} TfLiteUnidirectionalSequenceLSTMParams;
-
-typedef struct {
- // Parameters supported by version 1:
- // Parameters inherited for the LSTM kernel.
- TfLiteFusedActivation activation;
- float cell_clip;
- float proj_clip;
-
- // If true, store the outputs of both directions in the first output.
- bool merge_outputs;
-
- // Parameters supported by version 2:
- // If set to true then the first dimension is time, otherwise batch.
- bool time_major;
-
- // Parameters supported by version 4:
- // If set to true, then hybrid ops use asymmetric quantization for inputs.
- bool asymmetric_quantize_inputs;
-} TfLiteBidirectionalSequenceLSTMParams;
-
-typedef struct {
- bool align_corners;
- // half_pixel_centers assumes pixels are of half the actual dimensions, and
- // yields more accurate resizes. Corresponds to the same argument for the
- // original TensorFlow op in TF2.0.
- bool half_pixel_centers;
-} TfLiteResizeBilinearParams;
-
-typedef struct {
- bool align_corners;
- bool half_pixel_centers;
-} TfLiteResizeNearestNeighborParams;
-
-typedef struct {
- EmptyStructPlaceholder placeholder;
-} TfLitePadParams;
-
-typedef struct {
- EmptyStructPlaceholder placeholder;
-} TfLitePadV2Params;
-
-typedef struct {
- // TODO(ahentz): We can't have dynamic data in this struct, at least not yet.
- // For now we will fix the maximum possible number of dimensions.
- int shape[TFLITE_RESHAPE_PARAMS_MAX_DIMENSION_COUNT];
- int num_dimensions;
-} TfLiteReshapeParams;
-
-typedef struct {
- int ngram_size;
- int max_skip_size;
- bool include_all_ngrams;
-} TfLiteSkipGramParams;
-
-typedef struct {
- int block_size;
-} TfLiteSpaceToDepthParams;
-
-typedef struct {
- int block_size;
-} TfLiteDepthToSpaceParams;
-
-typedef struct {
- TfLiteType in_data_type;
- TfLiteType out_data_type;
-} TfLiteCastParams;
-
-typedef enum {
- kTfLiteCombinerTypeSum = 0,
- kTfLiteCombinerTypeMean = 1,
- kTfLiteCombinerTypeSqrtn = 2,
-} TfLiteCombinerType;
-
-typedef struct {
- TfLiteCombinerType combiner;
-} TfLiteEmbeddingLookupSparseParams;
-
-typedef struct {
- int axis;
-} TfLiteGatherParams;
-
-typedef struct {
- EmptyStructPlaceholder placeholder;
-} TfLiteTransposeParams;
-
-typedef struct {
- bool keep_dims;
-} TfLiteReducerParams;
-
-typedef struct {
- int num_splits;
-} TfLiteSplitParams;
-
-typedef struct {
- int num_splits;
-} TfLiteSplitVParams;
-
-typedef struct {
- // TODO(ahentz): We can't have dynamic data in this struct, at least not yet.
- // For now we will fix the maximum possible number of dimensions.
- int squeeze_dims[8];
- int num_squeeze_dims;
-} TfLiteSqueezeParams;
-
-typedef struct {
- int begin_mask;
- int end_mask;
- int ellipsis_mask;
- int new_axis_mask;
- int shrink_axis_mask;
-} TfLiteStridedSliceParams;
-
-typedef struct {
- TfLiteType output_type;
-} TfLiteArgMaxParams;
-
-typedef struct {
- TfLiteType output_type;
-} TfLiteArgMinParams;
-
-typedef struct {
- TfLitePadding padding;
- int stride_width;
- int stride_height;
-} TfLiteTransposeConvParams;
-
-typedef struct {
- bool validate_indices;
-} TfLiteSparseToDenseParams;
-
-typedef struct {
- TfLiteType out_type;
-} TfLiteShapeParams;
-
-typedef struct {
- EmptyStructPlaceholder placeholder;
-} TfLiteRankParams;
-
-typedef struct {
- // Parameters supported by version 1:
- float min;
- float max;
- int num_bits;
-
- // Parameters supported by version 2:
- bool narrow_range;
-} TfLiteFakeQuantParams;
-
-typedef struct {
- int values_count;
- int axis;
-} TfLitePackParams;
-
-typedef struct {
- int axis;
-} TfLiteOneHotParams;
-
-typedef struct {
- int num;
- int axis;
-} TfLiteUnpackParams;
-
-typedef struct {
- float alpha;
-} TfLiteLeakyReluParams;
-
-typedef struct {
- TfLiteType index_out_type;
-} TfLiteUniqueParams;
-
-typedef struct {
- int seq_dim;
- int batch_dim;
-} TfLiteReverseSequenceParams;
-
-typedef struct {
- EmptyStructPlaceholder placeholder;
-} TfLiteMatrixDiagParams;
-
-typedef struct {
- EmptyStructPlaceholder placeholder;
-} TfLiteMatrixSetDiagParams;
-
-typedef struct {
- int then_subgraph_index;
- int else_subgraph_index;
-} TfLiteIfParams;
-
-typedef struct {
- int cond_subgraph_index;
- int body_subgraph_index;
-} TfLiteWhileParams;
-
-#ifdef __cplusplus
-} // extern "C"
-#endif // __cplusplus
-
-#endif // TENSORFLOW_LITE_C_BUILTIN_OP_DATA_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/c/common.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/c/common.h
deleted file mode 100644
index 7ef173c78d2f53af0694df9c7783ba3eabebbdce..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/c/common.h
+++ /dev/null
@@ -1,936 +0,0 @@
-/* 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.
-==============================================================================*/
-
-// This file defines common C types and APIs for implementing operations,
-// delegates and other constructs in TensorFlow Lite. The actual operations and
-// delegates can be defined using C++, but the interface between the interpreter
-// and the operations are C.
-//
-// Summary of abstractions
-// TF_LITE_ENSURE - Self-sufficient error checking
-// TfLiteStatus - Status reporting
-// TfLiteIntArray - stores tensor shapes (dims),
-// TfLiteContext - allows an op to access the tensors
-// TfLiteTensor - tensor (a multidimensional array)
-// TfLiteNode - a single node or operation
-// TfLiteRegistration - the implementation of a conceptual operation.
-// TfLiteDelegate - allows delegation of nodes to alternative backends.
-//
-// Some abstractions in this file are created and managed by Interpreter.
-//
-// NOTE: The order of values in these structs are "semi-ABI stable". New values
-// should be added only to the end of structs and never reordered.
-
-#ifndef TENSORFLOW_LITE_C_COMMON_H_
-#define TENSORFLOW_LITE_C_COMMON_H_
-
-#include
-#include
-#include
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
-
-typedef enum TfLiteStatus {
- kTfLiteOk = 0,
- kTfLiteError = 1,
- kTfLiteDelegateError = 2
-} TfLiteStatus;
-
-// The list of external context types known to TF Lite. This list exists solely
-// to avoid conflicts and to ensure ops can share the external contexts they
-// need. Access to the external contexts is controlled by one of the
-// corresponding support files.
-typedef enum TfLiteExternalContextType {
- kTfLiteEigenContext = 0, // include eigen_support.h to use.
- kTfLiteGemmLowpContext = 1, // include gemm_support.h to use.
- kTfLiteEdgeTpuContext = 2, // Placeholder for Edge TPU support.
- kTfLiteCpuBackendContext = 3, // include cpu_backend_context.h to use.
- kTfLiteMaxExternalContexts = 4
-} TfLiteExternalContextType;
-
-// Forward declare so dependent structs and methods can reference these types
-// prior to the struct definitions.
-struct TfLiteContext;
-struct TfLiteDelegate;
-struct TfLiteRegistration;
-
-// An external context is a collection of information unrelated to the TF Lite
-// framework, but useful to a subset of the ops. TF Lite knows very little
-// about about the actual contexts, but it keeps a list of them, and is able to
-// refresh them if configurations like the number of recommended threads
-// change.
-typedef struct TfLiteExternalContext {
- TfLiteExternalContextType type;
- TfLiteStatus (*Refresh)(struct TfLiteContext* context);
-} TfLiteExternalContext;
-
-#define kTfLiteOptionalTensor (-1)
-
-// Fixed size list of integers. Used for dimensions and inputs/outputs tensor
-// indices
-typedef struct TfLiteIntArray {
- int size;
-// gcc 6.1+ have a bug where flexible members aren't properly handled
-// https://github.com/google/re2/commit/b94b7cd42e9f02673cd748c1ac1d16db4052514c
-#if (!defined(__clang__) && defined(__GNUC__) && __GNUC__ == 6 && \
- __GNUC_MINOR__ >= 1) || \
- defined(HEXAGON)
- int data[0];
-#else
- int data[];
-#endif
-} TfLiteIntArray;
-
-// Given the size (number of elements) in a TfLiteIntArray, calculate its size
-// in bytes.
-int TfLiteIntArrayGetSizeInBytes(int size);
-
-#ifndef TF_LITE_STATIC_MEMORY
-// Create a array of a given `size` (uninitialized entries).
-// This returns a pointer, that you must free using TfLiteIntArrayFree().
-TfLiteIntArray* TfLiteIntArrayCreate(int size);
-#endif
-
-// Check if two intarrays are equal. Returns 1 if they are equal, 0 otherwise.
-int TfLiteIntArrayEqual(const TfLiteIntArray* a, const TfLiteIntArray* b);
-
-// Check if an intarray equals an array. Returns 1 if equals, 0 otherwise.
-int TfLiteIntArrayEqualsArray(const TfLiteIntArray* a, int b_size,
- const int b_data[]);
-
-#ifndef TF_LITE_STATIC_MEMORY
-// Create a copy of an array passed as `src`.
-// You are expected to free memory with TfLiteIntArrayFree
-TfLiteIntArray* TfLiteIntArrayCopy(const TfLiteIntArray* src);
-
-// Free memory of array `a`.
-void TfLiteIntArrayFree(TfLiteIntArray* a);
-#endif // TF_LITE_STATIC_MEMORY
-
-// Fixed size list of floats. Used for per-channel quantization.
-typedef struct TfLiteFloatArray {
- int size;
-// gcc 6.1+ have a bug where flexible members aren't properly handled
-// https://github.com/google/re2/commit/b94b7cd42e9f02673cd748c1ac1d16db4052514c
-// This also applies to the toolchain used for Qualcomm Hexagon DSPs.
-#if !defined(__clang__) && defined(__GNUC__) && __GNUC__ == 6 && \
- __GNUC_MINOR__ >= 1
- float data[0];
-#else
- float data[];
-#endif
-} TfLiteFloatArray;
-
-// Given the size (number of elements) in a TfLiteFloatArray, calculate its size
-// in bytes.
-int TfLiteFloatArrayGetSizeInBytes(int size);
-
-#ifndef TF_LITE_STATIC_MEMORY
-// Create a array of a given `size` (uninitialized entries).
-// This returns a pointer, that you must free using TfLiteFloatArrayFree().
-TfLiteFloatArray* TfLiteFloatArrayCreate(int size);
-
-// Free memory of array `a`.
-void TfLiteFloatArrayFree(TfLiteFloatArray* a);
-#endif // TF_LITE_STATIC_MEMORY
-
-// Since we must not depend on any libraries, define a minimal subset of
-// error macros while avoiding names that have pre-conceived meanings like
-// assert and check.
-
-// Try to make all reporting calls through TF_LITE_KERNEL_LOG rather than
-// calling the context->ReportError function directly, so that message strings
-// can be stripped out if the binary size needs to be severely optimized.
-#ifndef TF_LITE_STRIP_ERROR_STRINGS
-#define TF_LITE_KERNEL_LOG(context, ...) \
- do { \
- (context)->ReportError((context), __VA_ARGS__); \
- } while (false)
-
-#define TF_LITE_MAYBE_KERNEL_LOG(context, ...) \
- do { \
- if ((context) != nullptr) { \
- (context)->ReportError((context), __VA_ARGS__); \
- } \
- } while (false)
-#else // TF_LITE_STRIP_ERROR_STRINGS
-#define TF_LITE_KERNEL_LOG(context, ...)
-#define TF_LITE_MAYBE_KERNEL_LOG(context, ...)
-#endif // TF_LITE_STRIP_ERROR_STRINGS
-
-// Check whether value is true, and if not return kTfLiteError from
-// the current function (and report the error string msg).
-#define TF_LITE_ENSURE_MSG(context, value, msg) \
- do { \
- if (!(value)) { \
- TF_LITE_KERNEL_LOG((context), __FILE__ " " msg); \
- return kTfLiteError; \
- } \
- } while (0)
-
-// Check whether the value `a` is true, and if not return kTfLiteError from
-// the current function, while also reporting the location of the error.
-#define TF_LITE_ENSURE(context, a) \
- do { \
- if (!(a)) { \
- TF_LITE_KERNEL_LOG((context), "%s:%d %s was not true.", __FILE__, \
- __LINE__, #a); \
- return kTfLiteError; \
- } \
- } while (0)
-
-#define TF_LITE_ENSURE_STATUS(a) \
- do { \
- const TfLiteStatus s = (a); \
- if (s != kTfLiteOk) { \
- return s; \
- } \
- } while (0)
-
-// Check whether the value `a == b` is true, and if not return kTfLiteError from
-// the current function, while also reporting the location of the error.
-// `a` and `b` may be evaluated more than once, so no side effects or
-// extremely expensive computations should be done.
-// NOTE: Use TF_LITE_ENSURE_TYPES_EQ if comparing TfLiteTypes.
-#define TF_LITE_ENSURE_EQ(context, a, b) \
- do { \
- if ((a) != (b)) { \
- TF_LITE_KERNEL_LOG((context), "%s:%d %s != %s (%d != %d)", __FILE__, \
- __LINE__, #a, #b, (a), (b)); \
- return kTfLiteError; \
- } \
- } while (0)
-
-#define TF_LITE_ENSURE_TYPES_EQ(context, a, b) \
- do { \
- if ((a) != (b)) { \
- TF_LITE_KERNEL_LOG((context), "%s:%d %s != %s (%s != %s)", __FILE__, \
- __LINE__, #a, #b, TfLiteTypeGetName(a), \
- TfLiteTypeGetName(b)); \
- return kTfLiteError; \
- } \
- } while (0)
-
-#define TF_LITE_ENSURE_OK(context, status) \
- do { \
- const TfLiteStatus s = (status); \
- if ((s) != kTfLiteOk) { \
- return s; \
- } \
- } while (0)
-
-// Define TFL_CAPI_EXPORT macro to export a function properly with a shared
-// library.
-#ifdef SWIG
-#define TFL_CAPI_EXPORT
-#else
-#if defined(_WIN32)
-#ifdef TFL_COMPILE_LIBRARY
-#define TFL_CAPI_EXPORT __declspec(dllexport)
-#else
-#define TFL_CAPI_EXPORT __declspec(dllimport)
-#endif // TFL_COMPILE_LIBRARY
-#else
-#define TFL_CAPI_EXPORT __attribute__((visibility("default")))
-#endif // _WIN32
-#endif // SWIG
-
-// Single-precision complex data type compatible with the C99 definition.
-typedef struct TfLiteComplex64 {
- float re, im; // real and imaginary parts, respectively.
-} TfLiteComplex64;
-
-// Double-precision complex data type compatible with the C99 definition.
-typedef struct TfLiteComplex128 {
- double re, im; // real and imaginary parts, respectively.
-} TfLiteComplex128;
-
-// Half precision data type compatible with the C99 definition.
-typedef struct TfLiteFloat16 {
- uint16_t data;
-} TfLiteFloat16;
-
-// Types supported by tensor
-typedef enum {
- kTfLiteNoType = 0,
- kTfLiteFloat32 = 1,
- kTfLiteInt32 = 2,
- kTfLiteUInt8 = 3,
- kTfLiteInt64 = 4,
- kTfLiteString = 5,
- kTfLiteBool = 6,
- kTfLiteInt16 = 7,
- kTfLiteComplex64 = 8,
- kTfLiteInt8 = 9,
- kTfLiteFloat16 = 10,
- kTfLiteFloat64 = 11,
- kTfLiteComplex128 = 12,
-} TfLiteType;
-
-// Return the name of a given type, for error reporting purposes.
-const char* TfLiteTypeGetName(TfLiteType type);
-
-// SupportedQuantizationTypes.
-typedef enum TfLiteQuantizationType {
- // No quantization.
- kTfLiteNoQuantization = 0,
- // Affine quantization (with support for per-channel quantization).
- // Corresponds to TfLiteAffineQuantization.
- kTfLiteAffineQuantization = 1,
-} TfLiteQuantizationType;
-
-// Structure specifying the quantization used by the tensor, if-any.
-typedef struct TfLiteQuantization {
- // The type of quantization held by params.
- TfLiteQuantizationType type;
- // Holds a reference to one of the quantization param structures specified
- // below.
- void* params;
-} TfLiteQuantization;
-
-// Legacy. Will be deprecated in favor of TfLiteAffineQuantization.
-// If per-layer quantization is specified this field will still be populated in
-// addition to TfLiteAffineQuantization.
-// Parameters for asymmetric quantization. Quantized values can be converted
-// back to float using:
-// real_value = scale * (quantized_value - zero_point)
-typedef struct TfLiteQuantizationParams {
- float scale;
- int32_t zero_point;
-} TfLiteQuantizationParams;
-
-// Parameters for asymmetric quantization across a dimension (i.e per output
-// channel quantization).
-// quantized_dimension specifies which dimension the scales and zero_points
-// correspond to.
-// For a particular value in quantized_dimension, quantized values can be
-// converted back to float using:
-// real_value = scale * (quantized_value - zero_point)
-typedef struct TfLiteAffineQuantization {
- TfLiteFloatArray* scale;
- TfLiteIntArray* zero_point;
- int32_t quantized_dimension;
-} TfLiteAffineQuantization;
-
-/* A union of pointers that points to memory for a given tensor. */
-typedef union TfLitePtrUnion {
- /* Do not access these members directly, if possible, use
- * GetTensorData(tensor) instead, otherwise only access .data, as other
- * members are deprecated. */
- int32_t* i32;
- int64_t* i64;
- float* f;
- TfLiteFloat16* f16;
- double* f64;
- char* raw;
- const char* raw_const;
- uint8_t* uint8;
- bool* b;
- int16_t* i16;
- TfLiteComplex64* c64;
- TfLiteComplex128* c128;
- int8_t* int8;
- /* Only use this member. */
- void* data;
-} TfLitePtrUnion;
-
-// Memory allocation strategies.
-// * kTfLiteMmapRo: Read-only memory-mapped data, or data externally allocated.
-// * kTfLiteArenaRw: Arena allocated with no guarantees about persistence,
-// and available during eval.
-// * kTfLiteArenaRwPersistent: Arena allocated but persistent across eval, and
-// only available during eval.
-// * kTfLiteDynamic: Allocated during eval, or for string tensors.
-// * kTfLitePersistentRo: Allocated and populated during prepare. This is
-// useful for tensors that can be computed during prepare and treated
-// as constant inputs for downstream ops (also in prepare).
-typedef enum TfLiteAllocationType {
- kTfLiteMemNone = 0,
- kTfLiteMmapRo,
- kTfLiteArenaRw,
- kTfLiteArenaRwPersistent,
- kTfLiteDynamic,
- kTfLitePersistentRo,
-} TfLiteAllocationType;
-
-// The delegates should use zero or positive integers to represent handles.
-// -1 is reserved from unallocated status.
-typedef int TfLiteBufferHandle;
-enum {
- kTfLiteNullBufferHandle = -1,
-};
-
-// Storage format of each dimension in a sparse tensor.
-typedef enum TfLiteDimensionType {
- kTfLiteDimDense = 0,
- kTfLiteDimSparseCSR,
-} TfLiteDimensionType;
-
-// Metadata to encode each dimension in a sparse tensor.
-typedef struct TfLiteDimensionMetadata {
- TfLiteDimensionType format;
- int dense_size;
- TfLiteIntArray* array_segments;
- TfLiteIntArray* array_indices;
-} TfLiteDimensionMetadata;
-
-// Parameters used to encode a sparse tensor. For detailed explanation of each
-// field please refer to lite/schema/schema.fbs.
-typedef struct TfLiteSparsity {
- TfLiteIntArray* traversal_order;
- TfLiteIntArray* block_map;
- TfLiteDimensionMetadata* dim_metadata;
- int dim_metadata_size;
-} TfLiteSparsity;
-
-// An tensor in the interpreter system which is a wrapper around a buffer of
-// data including a dimensionality (or NULL if not currently defined).
-#ifndef TF_LITE_STATIC_MEMORY
-typedef struct TfLiteTensor {
- // The data type specification for data stored in `data`. This affects
- // what member of `data` union should be used.
- TfLiteType type;
- // A union of data pointers. The appropriate type should be used for a typed
- // tensor based on `type`.
- TfLitePtrUnion data;
- // A pointer to a structure representing the dimensionality interpretation
- // that the buffer should have. NOTE: the product of elements of `dims`
- // and the element datatype size should be equal to `bytes` below.
- TfLiteIntArray* dims;
- // Quantization information.
- TfLiteQuantizationParams params;
- // How memory is mapped
- // kTfLiteMmapRo: Memory mapped read only.
- // i.e. weights
- // kTfLiteArenaRw: Arena allocated read write memory
- // (i.e. temporaries, outputs).
- TfLiteAllocationType allocation_type;
- // The number of bytes required to store the data of this Tensor. I.e.
- // (bytes of each element) * dims[0] * ... * dims[n-1]. For example, if
- // type is kTfLiteFloat32 and dims = {3, 2} then
- // bytes = sizeof(float) * 3 * 2 = 4 * 3 * 2 = 24.
- size_t bytes;
-
- // An opaque pointer to a tflite::MMapAllocation
- const void* allocation;
-
- // Null-terminated name of this tensor.
- const char* name;
-
- // The delegate which knows how to handle `buffer_handle`.
- // WARNING: This is an experimental interface that is subject to change.
- struct TfLiteDelegate* delegate;
-
- // An integer buffer handle that can be handled by `delegate`.
- // The value is valid only when delegate is not null.
- // WARNING: This is an experimental interface that is subject to change.
- TfLiteBufferHandle buffer_handle;
-
- // If the delegate uses its own buffer (e.g. GPU memory), the delegate is
- // responsible to set data_is_stale to true.
- // `delegate->CopyFromBufferHandle` can be called to copy the data from
- // delegate buffer.
- // WARNING: This is an // experimental interface that is subject to change.
- bool data_is_stale;
-
- // True if the tensor is a variable.
- bool is_variable;
-
- // Quantization information. Replaces params field above.
- TfLiteQuantization quantization;
-
- // Parameters used to encode a sparse tensor.
- // This is optional. The field is NULL if a tensor is dense.
- // WARNING: This is an experimental interface that is subject to change.
- TfLiteSparsity* sparsity;
-
- // Optional. Encodes shapes with unknown dimensions with -1. This field is
- // only populated when unknown dimensions exist in a read-write tensor (i.e.
- // an input or output tensor). (e.g. `dims` contains [1, 1, 1, 3] and
- // `dims_signature` contains [1, -1, -1, 3]).
- const TfLiteIntArray* dims_signature;
-} TfLiteTensor;
-
-// A structure representing an instance of a node.
-// This structure only exhibits the inputs, outputs and user defined data, not
-// other features like the type.
-typedef struct TfLiteNode {
- // Inputs to this node expressed as indices into the simulator's tensors.
- TfLiteIntArray* inputs;
-
- // Outputs to this node expressed as indices into the simulator's tensors.
- TfLiteIntArray* outputs;
-
- // intermediate tensors to this node expressed as indices into the simulator's
- // tensors.
- TfLiteIntArray* intermediates;
-
- // Temporary tensors uses during the computations. This usually contains no
- // tensors, but ops are allowed to change that if they need scratch space of
- // any sort.
- TfLiteIntArray* temporaries;
-
- // Opaque data provided by the node implementer through `Registration.init`.
- void* user_data;
-
- // Opaque data provided to the node if the node is a builtin. This is usually
- // a structure defined in builtin_op_data.h
- void* builtin_data;
-
- // Custom initial data. This is the opaque data provided in the flatbuffer.
- // WARNING: This is an experimental interface that is subject to change.
- const void* custom_initial_data;
- int custom_initial_data_size;
-
- // The pointer to the delegate. This is non-null only when the node is
- // created by calling `interpreter.ModifyGraphWithDelegate`.
- // WARNING: This is an experimental interface that is subject to change.
- struct TfLiteDelegate* delegate;
-} TfLiteNode;
-#else // defined(TF_LITE_STATIC_MEMORY)?
-// NOTE: This flag is opt-in only at compile time.
-//
-// Specific reduced TfLiteTensor struct for TF Micro runtime. This struct
-// contains only the minimum fields required to initialize and prepare a micro
-// inference graph. The fields in this struct have been ordered from
-// largest-to-smallest for optimal struct sizeof.
-//
-// This struct does not use:
-// - allocation
-// - buffer_handle
-// - data_is_stale
-// - delegate
-// - dims_signature
-// - name
-// - sparsity
-typedef struct TfLiteTensor {
- // TODO(b/155784997): Consider consolidating these quantization fields:
- // Quantization information. Replaces params field above.
- TfLiteQuantization quantization;
-
- // Quantization information.
- TfLiteQuantizationParams params;
-
- // A union of data pointers. The appropriate type should be used for a typed
- // tensor based on `type`.
- TfLitePtrUnion data;
-
- // A pointer to a structure representing the dimensionality interpretation
- // that the buffer should have. NOTE: the product of elements of `dims`
- // and the element datatype size should be equal to `bytes` below.
- TfLiteIntArray* dims;
-
- // The number of bytes required to store the data of this Tensor. I.e.
- // (bytes of each element) * dims[0] * ... * dims[n-1]. For example, if
- // type is kTfLiteFloat32 and dims = {3, 2} then
- // bytes = sizeof(float) * 3 * 2 = 4 * 3 * 2 = 24.
- size_t bytes;
-
- // The data type specification for data stored in `data`. This affects
- // what member of `data` union should be used.
- TfLiteType type;
-
- // How memory is mapped
- // kTfLiteMmapRo: Memory mapped read only.
- // i.e. weights
- // kTfLiteArenaRw: Arena allocated read write memory
- // (i.e. temporaries, outputs).
- TfLiteAllocationType allocation_type;
-
- // True if the tensor is a variable.
- bool is_variable;
-} TfLiteTensor;
-
-// Specific reduced TfLiteNode struct for TF Micro runtime. This struct contains
-// only the minimum fields required to represent a node.
-//
-// This struct does not use:
-// - delegate
-// - intermediates
-// - temporaries
-typedef struct TfLiteNode {
- // Inputs to this node expressed as indices into the simulator's tensors.
- TfLiteIntArray* inputs;
-
- // Outputs to this node expressed as indices into the simulator's tensors.
- TfLiteIntArray* outputs;
-
- // Opaque data provided by the node implementer through `Registration.init`.
- void* user_data;
-
- // Opaque data provided to the node if the node is a builtin. This is usually
- // a structure defined in builtin_op_data.h
- void* builtin_data;
-
- // Custom initial data. This is the opaque data provided in the flatbuffer.
- // WARNING: This is an experimental interface that is subject to change.
- const void* custom_initial_data;
- int custom_initial_data_size;
-} TfLiteNode;
-#endif // TF_LITE_STATIC_MEMORY
-
-// Light-weight tensor struct for TF Micro runtime. Provides the minimal amount
-// of information required for a kernel to run during TfLiteRegistration::Eval.
-// TODO(b/160955687): Move this field into TF_LITE_STATIC_MEMORY when TFLM
-// builds with this flag by default internally.
-typedef struct TfLiteEvalTensor {
- // A union of data pointers. The appropriate type should be used for a typed
- // tensor based on `type`.
- TfLitePtrUnion data;
-
- // A pointer to a structure representing the dimensionality interpretation
- // that the buffer should have.
- TfLiteIntArray* dims;
-
- // The data type specification for data stored in `data`. This affects
- // what member of `data` union should be used.
- TfLiteType type;
-} TfLiteEvalTensor;
-
-#ifndef TF_LITE_STATIC_MEMORY
-// Free data memory of tensor `t`.
-void TfLiteTensorDataFree(TfLiteTensor* t);
-
-// Free quantization data.
-void TfLiteQuantizationFree(TfLiteQuantization* quantization);
-
-// Free sparsity parameters.
-void TfLiteSparsityFree(TfLiteSparsity* sparsity);
-
-// Free memory of tensor `t`.
-void TfLiteTensorFree(TfLiteTensor* t);
-
-// Set all of a tensor's fields (and free any previously allocated data).
-void TfLiteTensorReset(TfLiteType type, const char* name, TfLiteIntArray* dims,
- TfLiteQuantizationParams quantization, char* buffer,
- size_t size, TfLiteAllocationType allocation_type,
- const void* allocation, bool is_variable,
- TfLiteTensor* tensor);
-
-// Resize the allocated data of a (dynamic) tensor. Tensors with allocation
-// types other than kTfLiteDynamic will be ignored.
-void TfLiteTensorRealloc(size_t num_bytes, TfLiteTensor* tensor);
-#endif // TF_LITE_STATIC_MEMORY
-
-// WARNING: This is an experimental interface that is subject to change.
-//
-// Currently, TfLiteDelegateParams has to be allocated in a way that it's
-// trivially destructable. It will be stored as `builtin_data` field in
-// `TfLiteNode` of the delegate node.
-//
-// See also the `CreateDelegateParams` function in `interpreter.cc` details.
-typedef struct TfLiteDelegateParams {
- struct TfLiteDelegate* delegate;
- TfLiteIntArray* nodes_to_replace;
- TfLiteIntArray* input_tensors;
- TfLiteIntArray* output_tensors;
-} TfLiteDelegateParams;
-
-typedef struct TfLiteContext {
- // Number of tensors in the context.
- size_t tensors_size;
-
- // The execution plan contains a list of the node indices in execution
- // order. execution_plan->size is the current number of nodes. And,
- // execution_plan->data[0] is the first node that needs to be run.
- // TfLiteDelegates can traverse the current execution plan by iterating
- // through each member of this array and using GetNodeAndRegistration() to
- // access details about a node. i.e.
- // TfLiteIntArray* execution_plan;
- // TF_LITE_ENSURE_STATUS(context->GetExecutionPlan(context, &execution_plan));
- // for (int exec_index = 0; exec_index < execution_plan->size; exec_index++) {
- // int node_index = execution_plan->data[exec_index];
- // TfLiteNode* node;
- // TfLiteRegistration* reg;
- // context->GetNodeAndRegistration(context, node_index, &node, ®);
- // }
- // WARNING: This is an experimental interface that is subject to change.
- TfLiteStatus (*GetExecutionPlan)(struct TfLiteContext* context,
- TfLiteIntArray** execution_plan);
-
- // An array of tensors in the interpreter context (of length `tensors_size`)
- TfLiteTensor* tensors;
-
- // opaque full context ptr (an opaque c++ data structure)
- void* impl_;
-
- // Request memory pointer be resized. Updates dimensions on the tensor.
- // NOTE: ResizeTensor takes ownership of newSize.
- TfLiteStatus (*ResizeTensor)(struct TfLiteContext*, TfLiteTensor* tensor,
- TfLiteIntArray* new_size);
- // Request that an error be reported with format string msg.
- void (*ReportError)(struct TfLiteContext*, const char* msg, ...);
-
- // Add `tensors_to_add` tensors, preserving pre-existing Tensor entries. If
- // non-null, the value pointed to by `first_new_tensor_index` will be set to
- // the index of the first new tensor.
- TfLiteStatus (*AddTensors)(struct TfLiteContext*, int tensors_to_add,
- int* first_new_tensor_index);
-
- // Get a Tensor node by node_index.
- // WARNING: This is an experimental interface that is subject to change.
- TfLiteStatus (*GetNodeAndRegistration)(
- struct TfLiteContext*, int node_index, TfLiteNode** node,
- struct TfLiteRegistration** registration);
-
- // Replace ops with one or more stub delegate operations. This function
- // does not take ownership of `nodes_to_replace`.
- TfLiteStatus (*ReplaceNodeSubsetsWithDelegateKernels)(
- struct TfLiteContext*, struct TfLiteRegistration registration,
- const TfLiteIntArray* nodes_to_replace, struct TfLiteDelegate* delegate);
-
- // Number of threads that are recommended to subsystems like gemmlowp and
- // eigen.
- int recommended_num_threads;
-
- // Access external contexts by type.
- // WARNING: This is an experimental interface that is subject to change.
- TfLiteExternalContext* (*GetExternalContext)(struct TfLiteContext*,
- TfLiteExternalContextType);
- // Set the value of a external context. Does not take ownership of the
- // pointer.
- // WARNING: This is an experimental interface that is subject to change.
- void (*SetExternalContext)(struct TfLiteContext*, TfLiteExternalContextType,
- TfLiteExternalContext*);
-
- // Flag for allowing float16 precision for FP32 calculation.
- // default: false.
- // WARNING: This is an experimental API and subject to change.
- bool allow_fp32_relax_to_fp16;
-
- // Pointer to the op-level profiler, if set; nullptr otherwise.
- void* profiler;
-
- // Allocate persistent buffer which has the same life time as the interpreter.
- // Returns nullptr on failure.
- // The memory is allocated from heap for TFL, and from tail in TFLM.
- // This method is only available in Init or Prepare stage.
- // WARNING: This is an experimental interface that is subject to change.
- void* (*AllocatePersistentBuffer)(struct TfLiteContext* ctx, size_t bytes);
-
- // Allocate a buffer which will be deallocated right after invoke phase.
- // The memory is allocated from heap in TFL, and from volatile arena in TFLM.
- // This method is only available in invoke stage.
- // NOTE: If possible use RequestScratchBufferInArena method to avoid memory
- // allocation during inference time.
- // WARNING: This is an experimental interface that is subject to change.
- TfLiteStatus (*AllocateBufferForEval)(struct TfLiteContext* ctx, size_t bytes,
- void** ptr);
-
- // Request a scratch buffer in the arena through static memory planning.
- // This method is only available in Prepare stage and the buffer is allocated
- // by the interpreter between Prepare and Eval stage. In Eval stage,
- // GetScratchBuffer API can be used to fetch the address.
- // WARNING: This is an experimental interface that is subject to change.
- TfLiteStatus (*RequestScratchBufferInArena)(struct TfLiteContext* ctx,
- size_t bytes, int* buffer_idx);
-
- // Get the scratch buffer pointer.
- // This method is only available in Eval stage.
- // WARNING: This is an experimental interface that is subject to change.
- void* (*GetScratchBuffer)(struct TfLiteContext* ctx, int buffer_idx);
-
- // Resize the memory pointer of the `tensor`. This method behaves the same as
- // `ResizeTensor`, except that it makes a copy of the shape array internally
- // so the shape array could be deallocated right afterwards.
- // WARNING: This is an experimental interface that is subject to change.
- TfLiteStatus (*ResizeTensorExplicit)(struct TfLiteContext* ctx,
- TfLiteTensor* tensor, int dims,
- const int* shape);
-
- // This method provides a preview of post-delegation partitioning. Each
- // TfLiteDelegateParams in the referenced array corresponds to one instance of
- // the delegate kernel.
- // Example usage:
- //
- // TfLiteIntArray* nodes_to_replace = ...;
- // TfLiteDelegateParams* params_array;
- // int num_partitions = 0;
- // TF_LITE_ENSURE_STATUS(context->PreviewDelegatePartitioning(
- // context, delegate, nodes_to_replace, ¶ms_array, &num_partitions));
- // for (int idx = 0; idx < num_partitions; idx++) {
- // const auto& partition_params = params_array[idx];
- // ...
- // }
- //
- // NOTE: The context owns the memory referenced by partition_params_array. It
- // will be cleared with another call to PreviewDelegateParitioning, or after
- // TfLiteDelegateParams::Prepare returns.
- //
- // WARNING: This is an experimental interface that is subject to change.
- TfLiteStatus (*PreviewDelegatePartitioning)(
- struct TfLiteContext* context, const TfLiteIntArray* nodes_to_replace,
- TfLiteDelegateParams** partition_params_array, int* num_partitions);
-
- // Returns a TfLiteTensor struct for a given index.
- // WARNING: This is an experimental interface that is subject to change.
- // WARNING: This method may not be available on all platforms.
- TfLiteTensor* (*GetTensor)(const struct TfLiteContext* context,
- int tensor_idx);
-
- // Returns a TfLiteEvalTensor struct for a given index.
- // WARNING: This is an experimental interface that is subject to change.
- // WARNING: This method may not be available on all platforms.
- TfLiteEvalTensor* (*GetEvalTensor)(const struct TfLiteContext* context,
- int tensor_idx);
-} TfLiteContext;
-
-typedef struct TfLiteRegistration {
- // Initializes the op from serialized data.
- // If a built-in op:
- // `buffer` is the op's params data (TfLiteLSTMParams*).
- // `length` is zero.
- // If custom op:
- // `buffer` is the op's `custom_options`.
- // `length` is the size of the buffer.
- //
- // Returns a type-punned (i.e. void*) opaque data (e.g. a primitive pointer
- // or an instance of a struct).
- //
- // The returned pointer will be stored with the node in the `user_data` field,
- // accessible within prepare and invoke functions below.
- // NOTE: if the data is already in the desired format, simply implement this
- // function to return `nullptr` and implement the free function to be a no-op.
- void* (*init)(TfLiteContext* context, const char* buffer, size_t length);
-
- // The pointer `buffer` is the data previously returned by an init invocation.
- void (*free)(TfLiteContext* context, void* buffer);
-
- // prepare is called when the inputs this node depends on have been resized.
- // context->ResizeTensor() can be called to request output tensors to be
- // resized.
- //
- // Returns kTfLiteOk on success.
- TfLiteStatus (*prepare)(TfLiteContext* context, TfLiteNode* node);
-
- // Execute the node (should read node->inputs and output to node->outputs).
- // Returns kTfLiteOk on success.
- TfLiteStatus (*invoke)(TfLiteContext* context, TfLiteNode* node);
-
- // profiling_string is called during summarization of profiling information
- // in order to group executions together. Providing a value here will cause a
- // given op to appear multiple times is the profiling report. This is
- // particularly useful for custom ops that can perform significantly
- // different calculations depending on their `user-data`.
- const char* (*profiling_string)(const TfLiteContext* context,
- const TfLiteNode* node);
-
- // Builtin codes. If this kernel refers to a builtin this is the code
- // of the builtin. This is so we can do marshaling to other frameworks like
- // NN API.
- // Note: It is the responsibility of the registration binder to set this
- // properly.
- int32_t builtin_code;
-
- // Custom op name. If the op is a builtin, this will be null.
- // Note: It is the responsibility of the registration binder to set this
- // properly.
- // WARNING: This is an experimental interface that is subject to change.
- const char* custom_name;
-
- // The version of the op.
- // Note: It is the responsibility of the registration binder to set this
- // properly.
- int version;
-} TfLiteRegistration;
-
-// The flags used in `TfLiteDelegate`. Note that this is a bitmask, so the
-// values should be 1, 2, 4, 8, ...etc.
-typedef enum TfLiteDelegateFlags {
- kTfLiteDelegateFlagsNone = 0,
- // The flag is set if the delegate can handle dynamic sized tensors.
- // For example, the output shape of a `Resize` op with non-constant shape
- // can only be inferred when the op is invoked.
- // In this case, the Delegate is responsible for calling
- // `SetTensorToDynamic` to mark the tensor as a dynamic tensor, and calling
- // `ResizeTensor` when invoking the op.
- //
- // If the delegate isn't capable to handle dynamic tensors, this flag need
- // to be set to false.
- kTfLiteDelegateFlagsAllowDynamicTensors = 1,
-
- // This flag can be used by delegates (that allow dynamic tensors) to ensure
- // applicable tensor shapes are automatically propagated in the case of tensor
- // resizing.
- // This means that non-dynamic (allocation_type != kTfLiteDynamic) I/O tensors
- // of a delegate kernel will have correct shapes before its Prepare() method
- // is called. The runtime leverages TFLite builtin ops in the original
- // execution plan to propagate shapes.
- //
- // A few points to note:
- // 1. This requires kTfLiteDelegateFlagsAllowDynamicTensors. If that flag is
- // false, this one is redundant since the delegate kernels are re-initialized
- // every time tensors are resized.
- // 2. Enabling this flag adds some overhead to AllocateTensors(), since extra
- // work is required to prepare the original execution plan.
- // 3. This flag requires that the original execution plan only have ops with
- // valid registrations (and not 'dummy' custom ops like with Flex).
- // WARNING: This feature is experimental and subject to change.
- kTfLiteDelegateFlagsRequirePropagatedShapes = 2
-} TfLiteDelegateFlags;
-
-// WARNING: This is an experimental interface that is subject to change.
-typedef struct TfLiteDelegate {
- // Data that delegate needs to identify itself. This data is owned by the
- // delegate. The delegate is owned in the user code, so the delegate is
- // responsible for doing this when it is destroyed.
- void* data_;
-
- // Invoked by ModifyGraphWithDelegate. This prepare is called, giving the
- // delegate a view of the current graph through TfLiteContext*. It typically
- // will look at the nodes and call ReplaceNodeSubsetsWithDelegateKernels()
- // to ask the TensorFlow lite runtime to create macro-nodes to represent
- // delegated subgraphs of the original graph.
- TfLiteStatus (*Prepare)(TfLiteContext* context,
- struct TfLiteDelegate* delegate);
-
- // Copy the data from delegate buffer handle into raw memory of the given
- // 'tensor'. Note that the delegate is allowed to allocate the raw bytes as
- // long as it follows the rules for kTfLiteDynamic tensors, in which case this
- // cannot be null.
- TfLiteStatus (*CopyFromBufferHandle)(TfLiteContext* context,
- struct TfLiteDelegate* delegate,
- TfLiteBufferHandle buffer_handle,
- TfLiteTensor* tensor);
-
- // Copy the data from raw memory of the given 'tensor' to delegate buffer
- // handle. This can be null if the delegate doesn't use its own buffer.
- TfLiteStatus (*CopyToBufferHandle)(TfLiteContext* context,
- struct TfLiteDelegate* delegate,
- TfLiteBufferHandle buffer_handle,
- TfLiteTensor* tensor);
-
- // Free the Delegate Buffer Handle. Note: This only frees the handle, but
- // this doesn't release the underlying resource (e.g. textures). The
- // resources are either owned by application layer or the delegate.
- // This can be null if the delegate doesn't use its own buffer.
- void (*FreeBufferHandle)(TfLiteContext* context,
- struct TfLiteDelegate* delegate,
- TfLiteBufferHandle* handle);
-
- // Bitmask flags. See the comments in `TfLiteDelegateFlags`.
- int64_t flags;
-} TfLiteDelegate;
-
-// Build a 'null' delegate, with all the fields properly set to their default
-// values.
-TfLiteDelegate TfLiteDelegateCreate();
-
-#ifdef __cplusplus
-} // extern "C"
-#endif // __cplusplus
-#endif // TENSORFLOW_LITE_C_COMMON_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/error_reporter.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/error_reporter.h
deleted file mode 100644
index 05839a611c776edd96bbb5670100b66a17f0af8b..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/error_reporter.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Copyright 2017 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_
-#define TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_
-
-#include
-
-namespace tflite {
-
-/// A functor that reports error to supporting system. Invoked similar to
-/// printf.
-///
-/// Usage:
-/// ErrorReporter foo;
-/// foo.Report("test %d", 5);
-/// or
-/// va_list args;
-/// foo.Report("test %d", args); // where args is va_list
-///
-/// Subclass ErrorReporter to provide another reporting destination.
-/// For example, if you have a GUI program, you might redirect to a buffer
-/// that drives a GUI error log box.
-class ErrorReporter {
- public:
- virtual ~ErrorReporter() {}
- virtual int Report(const char* format, va_list args) = 0;
- int Report(const char* format, ...);
- int ReportError(void*, const char* format, ...);
-};
-
-} // namespace tflite
-
-// You should not make bare calls to the error reporter, instead use the
-// TF_LITE_REPORT_ERROR macro, since this allows message strings to be
-// stripped when the binary size has to be optimized. If you are looking to
-// reduce binary size, define TF_LITE_STRIP_ERROR_STRINGS when compiling and
-// every call will be stubbed out, taking no memory.
-#ifndef TF_LITE_STRIP_ERROR_STRINGS
-#define TF_LITE_REPORT_ERROR(reporter, ...) \
- do { \
- static_cast(reporter)->Report(__VA_ARGS__); \
- } while (false)
-#else // TF_LITE_STRIP_ERROR_STRINGS
-#define TF_LITE_REPORT_ERROR(reporter, ...)
-#endif // TF_LITE_STRIP_ERROR_STRINGS
-
-#endif // TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/flatbuffer_conversions.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/flatbuffer_conversions.h
deleted file mode 100644
index aaeb98c0a2e6b067a0d4c7bd0c5b7a8170be9af8..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/flatbuffer_conversions.h
+++ /dev/null
@@ -1,253 +0,0 @@
-/* Copyright 2018 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_CORE_API_FLATBUFFER_CONVERSIONS_H_
-#define TENSORFLOW_LITE_CORE_API_FLATBUFFER_CONVERSIONS_H_
-
-// These functions transform codes and data structures that are defined in the
-// flatbuffer serialization format into in-memory values that are used by the
-// runtime API and interpreter.
-
-#include
-#include
-#include
-
-#include "tensorflow/lite/c/common.h"
-#include "tensorflow/lite/core/api/error_reporter.h"
-#include "tensorflow/lite/schema/schema_generated.h"
-
-namespace tflite {
-
-// Interface class for builtin data allocations.
-class BuiltinDataAllocator {
- public:
- virtual void* Allocate(size_t size, size_t alignment_hint) = 0;
- virtual void Deallocate(void* data) = 0;
-
- // Allocate a structure, but make sure it is a POD structure that doesn't
- // require constructors to run. The reason we do this, is that Interpreter's C
- // extension part will take ownership so destructors will not be run during
- // deallocation.
- template
- T* AllocatePOD() {
- // TODO(b/154346074): Change this to is_trivially_destructible when all
- // platform targets support that properly.
- static_assert(std::is_pod::value, "Builtin data structure must be POD.");
- void* allocated_memory = this->Allocate(sizeof(T), alignof(T));
- return new (allocated_memory) T;
- }
-
- virtual ~BuiltinDataAllocator() {}
-};
-
-// Parse the appropriate data out of the op.
-//
-// This handles builtin data explicitly as there are flatbuffer schemas.
-// If it returns kTfLiteOk, it passes the data out with `builtin_data`. The
-// calling function has to pass in an allocator object, and this allocator
-// will be called to reserve space for the output data. If the calling
-// function's allocator reserves memory on the heap, then it's the calling
-// function's responsibility to free it.
-// If it returns kTfLiteError, `builtin_data` will be `nullptr`.
-TfLiteStatus ParseOpData(const Operator* op, BuiltinOperator op_type,
- ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-// Converts the tensor data type used in the flat buffer to the representation
-// used by the runtime.
-TfLiteStatus ConvertTensorType(TensorType tensor_type, TfLiteType* type,
- ErrorReporter* error_reporter);
-
-TfLiteStatus ParseAbs(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseAdd(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseArgMax(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseArgMin(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseCeil(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseConcatenation(const Operator* op,
- ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseConv2D(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseCos(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseDepthwiseConv2D(const Operator* op,
- ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseDequantize(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseEqual(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseFloor(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseFullyConnected(const Operator* op,
- ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseGreater(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseGreaterEqual(const Operator* op,
- ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseHardSwish(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseL2Normalization(const Operator* op,
- ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseLess(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseLessEqual(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseLog(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseLogicalAnd(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseLogicalNot(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseLogicalOr(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseLogistic(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseMaximum(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseMinimum(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseMul(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseNeg(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseNotEqual(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParsePack(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParsePad(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParsePadV2(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParsePool(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParsePrelu(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseQuantize(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseReducer(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseRelu(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseRelu6(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseReshape(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseResizeNearestNeighbor(const Operator* op,
- ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseRound(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseRsqrt(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseSin(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseSoftmax(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseSplit(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseSqrt(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseSquare(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseStridedSlice(const Operator* op,
- ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator,
- void** builtin_data);
-
-TfLiteStatus ParseSub(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseSvdf(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseTanh(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-TfLiteStatus ParseUnpack(const Operator* op, ErrorReporter* error_reporter,
- BuiltinDataAllocator* allocator, void** builtin_data);
-
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_CORE_API_FLATBUFFER_CONVERSIONS_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/op_resolver.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/op_resolver.h
deleted file mode 100644
index 1294b7b8ea812f4c17d829455ca88a0687e827b0..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/op_resolver.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* Copyright 2018 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_
-#define TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_
-
-#include "tensorflow/lite/c/common.h"
-#include "tensorflow/lite/core/api/error_reporter.h"
-#include "tensorflow/lite/schema/schema_generated.h"
-
-namespace tflite {
-
-/// Abstract interface that returns TfLiteRegistrations given op codes or custom
-/// op names. This is the mechanism that ops being referenced in the flatbuffer
-/// model are mapped to executable function pointers (TfLiteRegistrations).
-class OpResolver {
- public:
- /// Finds the op registration for a builtin operator by enum code.
- virtual const TfLiteRegistration* FindOp(tflite::BuiltinOperator op,
- int version) const = 0;
- /// Finds the op registration of a custom operator by op name.
- virtual const TfLiteRegistration* FindOp(const char* op,
- int version) const = 0;
- virtual ~OpResolver() {}
-};
-
-// Handles the logic for converting between an OperatorCode structure extracted
-// from a flatbuffer and information about a registered operator
-// implementation.
-TfLiteStatus GetRegistrationFromOpCode(const OperatorCode* opcode,
- const OpResolver& op_resolver,
- ErrorReporter* error_reporter,
- const TfLiteRegistration** registration);
-
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/profiler.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/profiler.h
deleted file mode 100644
index 897efbe1438b677f330c102a3591c008db76d973..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/profiler.h
+++ /dev/null
@@ -1,194 +0,0 @@
-/* Copyright 2017 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_CORE_API_PROFILER_H_
-#define TENSORFLOW_LITE_CORE_API_PROFILER_H_
-
-#include
-
-namespace tflite {
-
-// A simple utility for enabling profiled event tracing in TensorFlow Lite.
-class Profiler {
- public:
- // As certain Profiler instance might be only interested in certain event
- // types, we define each event type value to allow a Profiler to use
- // bitmasking bitwise operations to determine whether an event should be
- // recorded or not.
- enum class EventType {
- // Default event type, the metadata field has no special significance.
- DEFAULT = 1,
-
- // The event is an operator invocation and the event_metadata field is the
- // index of operator node.
- OPERATOR_INVOKE_EVENT = 2,
-
- // The event is an invocation for an internal operator of a TFLite delegate.
- // The event_metadata field is the index of operator node that's specific to
- // the delegate.
- DELEGATE_OPERATOR_INVOKE_EVENT = 4,
-
- // The event is a recording of runtime instrumentation such as the overall
- // TFLite runtime status, the TFLite delegate status (if a delegate
- // is applied), and the overall model inference latency etc.
- // Note, the delegate status and overall status are stored as separate
- // event_metadata fields. In particular, the delegate status is encoded
- // as DelegateStatus::full_status().
- GENERAL_RUNTIME_INSTRUMENTATION_EVENT = 8,
- };
-
- virtual ~Profiler() {}
-
- // Signals the beginning of an event and returns a handle to the profile
- // event. The `event_metadata1` and `event_metadata2` have different
- // interpretations based on the actual Profiler instance and the `event_type`.
- // For example, as for the 'SubgraphAwareProfiler' defined in
- // lite/core/subgraph.h, when the event_type is OPERATOR_INVOKE_EVENT,
- // `event_metadata1` represents the index of a TFLite node, and
- // `event_metadata2` represents the index of the subgraph that this event
- // comes from.
- virtual uint32_t BeginEvent(const char* tag, EventType event_type,
- int64_t event_metadata1,
- int64_t event_metadata2) = 0;
- // Similar w/ the above, but `event_metadata2` defaults to 0.
- uint32_t BeginEvent(const char* tag, EventType event_type,
- int64_t event_metadata) {
- return BeginEvent(tag, event_type, event_metadata, /*event_metadata2*/ 0);
- }
-
- // Signals an end to the specified profile event with 'event_metadata's, This
- // is useful when 'event_metadata's are not available when the event begins
- // or when one wants to overwrite the 'event_metadata's set at the beginning.
- virtual void EndEvent(uint32_t event_handle, int64_t event_metadata1,
- int64_t event_metadata2) {}
- // Signals an end to the specified profile event.
- virtual void EndEvent(uint32_t event_handle) = 0;
-
- // Appends an event of type 'event_type' with 'tag' and 'event_metadata'
- // which started at 'start' and ended at 'end'
- // Note:
- // In cases were ProfileSimmarizer and tensorflow::StatsCalculator are used
- // they assume the value is in "usec", if in any case subclasses
- // didn't put usec, then the values are not meaningful.
- // TODO karimnosseir: Revisit and make the function more clear.
- void AddEvent(const char* tag, EventType event_type, uint64_t start,
- uint64_t end, int64_t event_metadata) {
- AddEvent(tag, event_type, start, end, event_metadata,
- /*event_metadata2*/ 0);
- }
-
- virtual void AddEvent(const char* tag, EventType event_type, uint64_t start,
- uint64_t end, int64_t event_metadata1,
- int64_t event_metadata2) {}
-
- protected:
- friend class ScopedProfile;
-};
-
-// Adds a profile event to `profiler` that begins with the construction
-// of the object and ends when the object goes out of scope.
-// The lifetime of tag should be at least the lifetime of `profiler`.
-// `profiler` may be null, in which case nothing is profiled.
-class ScopedProfile {
- public:
- ScopedProfile(Profiler* profiler, const char* tag,
- Profiler::EventType event_type = Profiler::EventType::DEFAULT,
- int64_t event_metadata = 0)
- : profiler_(profiler), event_handle_(0) {
- if (profiler) {
- event_handle_ = profiler_->BeginEvent(tag, event_type, event_metadata);
- }
- }
-
- ~ScopedProfile() {
- if (profiler_) {
- profiler_->EndEvent(event_handle_);
- }
- }
-
- protected:
- Profiler* profiler_;
- uint32_t event_handle_;
-};
-
-class ScopedOperatorProfile : public ScopedProfile {
- public:
- ScopedOperatorProfile(Profiler* profiler, const char* tag, int node_index)
- : ScopedProfile(profiler, tag, Profiler::EventType::OPERATOR_INVOKE_EVENT,
- static_cast(node_index)) {}
-};
-
-class ScopedDelegateOperatorProfile : public ScopedProfile {
- public:
- ScopedDelegateOperatorProfile(Profiler* profiler, const char* tag,
- int node_index)
- : ScopedProfile(profiler, tag,
- Profiler::EventType::DELEGATE_OPERATOR_INVOKE_EVENT,
- static_cast(node_index)) {}
-};
-
-class ScopedRuntimeInstrumentationProfile : public ScopedProfile {
- public:
- ScopedRuntimeInstrumentationProfile(Profiler* profiler, const char* tag)
- : ScopedProfile(
- profiler, tag,
- Profiler::EventType::GENERAL_RUNTIME_INSTRUMENTATION_EVENT, -1) {}
-
- void set_runtime_status(int64_t delegate_status, int64_t interpreter_status) {
- if (profiler_) {
- delegate_status_ = delegate_status;
- interpreter_status_ = interpreter_status;
- }
- }
-
- ~ScopedRuntimeInstrumentationProfile() {
- if (profiler_) {
- profiler_->EndEvent(event_handle_, delegate_status_, interpreter_status_);
- }
- }
-
- private:
- int64_t delegate_status_;
- int64_t interpreter_status_;
-};
-
-} // namespace tflite
-
-#define TFLITE_VARNAME_UNIQ_IMPL(name, ctr) name##ctr
-#define TFLITE_VARNAME_UNIQ(name, ctr) TFLITE_VARNAME_UNIQ_IMPL(name, ctr)
-
-#define TFLITE_SCOPED_TAGGED_DEFAULT_PROFILE(profiler, tag) \
- tflite::ScopedProfile TFLITE_VARNAME_UNIQ(_profile_, __COUNTER__)( \
- (profiler), (tag))
-
-#define TFLITE_SCOPED_TAGGED_OPERATOR_PROFILE(profiler, tag, node_index) \
- tflite::ScopedOperatorProfile TFLITE_VARNAME_UNIQ(_profile_, __COUNTER__)( \
- (profiler), (tag), (node_index))
-
-#define TFLITE_SCOPED_DELEGATE_OPERATOR_PROFILE(profiler, tag, node_index) \
- tflite::ScopedDelegateOperatorProfile TFLITE_VARNAME_UNIQ( \
- _profile_, __COUNTER__)((profiler), (tag), (node_index))
-
-#define TFLITE_ADD_RUNTIME_INSTRUMENTATION_EVENT( \
- profiler, tag, delegate_status, interpreter_status) \
- do { \
- if (!profiler) { \
- const auto handle = profiler->BeginEvent( \
- tag, Profiler::EventType::GENERAL_RUNTIME_INSTRUMENTATION_EVENT, \
- delegate_status, interpreter_status); \
- profiler->EndEvent(handle); \
- } \
- } while (false);
-
-#endif // TENSORFLOW_LITE_CORE_API_PROFILER_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/tensor_utils.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/tensor_utils.h
deleted file mode 100644
index 9f1cf94a5ffbca1eea8d0e2d8b1bf21ceae914c7..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/core/api/tensor_utils.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* 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.
-==============================================================================*/
-
-#ifndef TENSORFLOW_LITE_CORE_API_TENSOR_UTILS_H_
-#define TENSORFLOW_LITE_CORE_API_TENSOR_UTILS_H_
-
-#include "tensorflow/lite/c/common.h"
-
-namespace tflite {
-
-// Resets a variable tensor to the default value.
-TfLiteStatus ResetVariableTensor(TfLiteTensor* tensor);
-
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_CORE_API_TENSOR_UTILS_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/common.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/common.h
deleted file mode 100644
index 66a2d977f3948ae9fcc02a835b5173bbb6e86651..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/common.h
+++ /dev/null
@@ -1,956 +0,0 @@
-/* Copyright 2017 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_COMMON_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_COMMON_H_
-
-#ifndef ALLOW_SLOW_GENERIC_DEPTHWISECONV_FALLBACK
-#ifdef GEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK
-#define ALLOW_SLOW_GENERIC_DEPTHWISECONV_FALLBACK
-#endif
-#endif
-
-#include
-
-#include "fixedpoint/fixedpoint.h"
-#include "tensorflow/lite/kernels/internal/cppmath.h"
-#include "tensorflow/lite/kernels/internal/optimized/neon_check.h"
-#include "tensorflow/lite/kernels/internal/types.h"
-
-namespace tflite {
-
-constexpr int kReverseShift = -1;
-
-inline void GetActivationMinMax(FusedActivationFunctionType ac,
- float* output_activation_min,
- float* output_activation_max) {
- switch (ac) {
- case FusedActivationFunctionType::kNone:
- *output_activation_min = std::numeric_limits::lowest();
- *output_activation_max = std::numeric_limits::max();
- break;
- case FusedActivationFunctionType::kRelu:
- *output_activation_min = 0.f;
- *output_activation_max = std::numeric_limits::max();
- break;
- case FusedActivationFunctionType::kRelu1:
- *output_activation_min = -1.f;
- *output_activation_max = 1.f;
- break;
- case FusedActivationFunctionType::kRelu6:
- *output_activation_min = 0.f;
- *output_activation_max = 6.f;
- break;
- }
-}
-
-template
-inline T ActivationFunctionWithMinMax(T x, T output_activation_min,
- T output_activation_max) {
- using std::max;
- using std::min;
- return min(max(x, output_activation_min), output_activation_max);
-}
-
-// Legacy function, left for compatibility only.
-template
-float ActivationFunction(float x) {
- float output_activation_min, output_activation_max;
- GetActivationMinMax(Ac, &output_activation_min, &output_activation_max);
- return ActivationFunctionWithMinMax(x, output_activation_min,
- output_activation_max);
-}
-
-inline void BiasAndClamp(float clamp_min, float clamp_max, int bias_size,
- const float* bias_data, int array_size,
- float* array_data) {
- // Note: see b/132215220: in May 2019 we thought it would be OK to replace
- // this with the Eigen one-liner:
- // return (array.colwise() + bias).cwiseMin(clamp_max).cwiseMin(clamp_max).
- // This turned out to severely regress performance: +4ms (i.e. 8%) on
- // MobileNet v2 / 1.0 / 224. So we keep custom NEON code for now.
- TFLITE_DCHECK_EQ((array_size % bias_size), 0);
-#ifdef USE_NEON
- float* array_ptr = array_data;
- float* array_end_ptr = array_ptr + array_size;
- const auto clamp_min_vec = vdupq_n_f32(clamp_min);
- const auto clamp_max_vec = vdupq_n_f32(clamp_max);
- for (; array_ptr != array_end_ptr; array_ptr += bias_size) {
- int i = 0;
- for (; i <= bias_size - 16; i += 16) {
- auto b0 = vld1q_f32(bias_data + i);
- auto b1 = vld1q_f32(bias_data + i + 4);
- auto b2 = vld1q_f32(bias_data + i + 8);
- auto b3 = vld1q_f32(bias_data + i + 12);
- auto a0 = vld1q_f32(array_ptr + i);
- auto a1 = vld1q_f32(array_ptr + i + 4);
- auto a2 = vld1q_f32(array_ptr + i + 8);
- auto a3 = vld1q_f32(array_ptr + i + 12);
- auto x0 = vaddq_f32(a0, b0);
- auto x1 = vaddq_f32(a1, b1);
- auto x2 = vaddq_f32(a2, b2);
- auto x3 = vaddq_f32(a3, b3);
- x0 = vmaxq_f32(clamp_min_vec, x0);
- x1 = vmaxq_f32(clamp_min_vec, x1);
- x2 = vmaxq_f32(clamp_min_vec, x2);
- x3 = vmaxq_f32(clamp_min_vec, x3);
- x0 = vminq_f32(clamp_max_vec, x0);
- x1 = vminq_f32(clamp_max_vec, x1);
- x2 = vminq_f32(clamp_max_vec, x2);
- x3 = vminq_f32(clamp_max_vec, x3);
- vst1q_f32(array_ptr + i, x0);
- vst1q_f32(array_ptr + i + 4, x1);
- vst1q_f32(array_ptr + i + 8, x2);
- vst1q_f32(array_ptr + i + 12, x3);
- }
- for (; i <= bias_size - 4; i += 4) {
- auto b = vld1q_f32(bias_data + i);
- auto a = vld1q_f32(array_ptr + i);
- auto x = vaddq_f32(a, b);
- x = vmaxq_f32(clamp_min_vec, x);
- x = vminq_f32(clamp_max_vec, x);
- vst1q_f32(array_ptr + i, x);
- }
- for (; i < bias_size; i++) {
- array_ptr[i] = ActivationFunctionWithMinMax(array_ptr[i] + bias_data[i],
- clamp_min, clamp_max);
- }
- }
-#else // not NEON
- for (int array_offset = 0; array_offset < array_size;
- array_offset += bias_size) {
- for (int i = 0; i < bias_size; i++) {
- array_data[array_offset + i] = ActivationFunctionWithMinMax(
- array_data[array_offset + i] + bias_data[i], clamp_min, clamp_max);
- }
- }
-#endif
-}
-
-inline int32_t MultiplyByQuantizedMultiplierSmallerThanOneExp(
- int32_t x, int32_t quantized_multiplier, int left_shift) {
- using gemmlowp::RoundingDivideByPOT;
- using gemmlowp::SaturatingRoundingDoublingHighMul;
- return RoundingDivideByPOT(
- SaturatingRoundingDoublingHighMul(x, quantized_multiplier), -left_shift);
-}
-
-inline int32_t MultiplyByQuantizedMultiplierGreaterThanOne(
- int32_t x, int32_t quantized_multiplier, int left_shift) {
- using gemmlowp::SaturatingRoundingDoublingHighMul;
- return SaturatingRoundingDoublingHighMul(x * (1 << left_shift),
- quantized_multiplier);
-}
-
-inline int32_t MultiplyByQuantizedMultiplier(int32_t x,
- int32_t quantized_multiplier,
- int shift) {
- using gemmlowp::RoundingDivideByPOT;
- using gemmlowp::SaturatingRoundingDoublingHighMul;
- int left_shift = shift > 0 ? shift : 0;
- int right_shift = shift > 0 ? 0 : -shift;
- return RoundingDivideByPOT(SaturatingRoundingDoublingHighMul(
- x * (1 << left_shift), quantized_multiplier),
- right_shift);
-}
-
-inline int32_t MultiplyByQuantizedMultiplier(int64_t x,
- int32_t quantized_multiplier,
- int shift) {
- // Inputs:
- // - quantized_multiplier has fixed point at bit 31
- // - shift is -31 to +7 (negative for right shift)
- //
- // Assumptions: The following input ranges are assumed
- // - quantize_scale>=0 (the usual range is (1<<30) to (1>>31)-1)
- // - scaling is chosen so final scaled result fits in int32_t
- // - input x is in the range -(1<<47) <= x < (1<<47)
- assert(quantized_multiplier >= 0);
- assert(shift >= -31 && shift < 8);
-
- int32_t reduced_multiplier = (quantized_multiplier + (1 << 15)) >> 16;
- int total_shift = 15 - shift;
- x = (x * (int64_t)reduced_multiplier) + ((int64_t)1 << (total_shift - 1));
- int32_t result = x >> total_shift;
- return result;
-}
-
-template
-int CountLeadingZeros(T integer_input) {
- static_assert(std::is_unsigned::value,
- "Only unsigned integer types handled.");
-#if defined(__GNUC__)
- return integer_input ? __builtin_clz(integer_input)
- : std::numeric_limits::digits;
-#else
- if (integer_input == 0) {
- return std::numeric_limits::digits;
- }
-
- const T one_in_leading_positive = static_cast(1)
- << (std::numeric_limits::digits - 1);
- int leading_zeros = 0;
- while (integer_input < one_in_leading_positive) {
- integer_input <<= 1;
- ++leading_zeros;
- }
- return leading_zeros;
-#endif
-}
-
-template
-inline int CountLeadingSignBits(T integer_input) {
- static_assert(std::is_signed::value, "Only signed integer types handled.");
-#if defined(__GNUC__) && !defined(__clang__)
- return integer_input ? __builtin_clrsb(integer_input)
- : std::numeric_limits::digits;
-#else
- using U = typename std::make_unsigned::type;
- return integer_input >= 0
- ? CountLeadingZeros(static_cast(integer_input)) - 1
- : integer_input != std::numeric_limits::min()
- ? CountLeadingZeros(2 * static_cast(-integer_input) - 1)
- : 0;
-#endif
-}
-
-// Use "count leading zeros" helper functions to do a fast Floor(log_2(x)).
-template
-inline Integer FloorLog2(Integer n) {
- static_assert(std::is_integral::value, "");
- static_assert(std::is_signed::value, "");
- static_assert(sizeof(Integer) == 4 || sizeof(Integer) == 8, "");
- TFLITE_CHECK_GT(n, 0);
- if (sizeof(Integer) == 4) {
- return 30 - CountLeadingSignBits(n);
- } else {
- return 62 - CountLeadingSignBits(n);
- }
-}
-
-// generate INT16 LUT for function(), e.g., table exp(x) and 1/(1+x) used in
-// softmax
-inline void gen_lut(const std::function& func, double min,
- double max, int16_t* table, const int num) {
- // size of table should equal to num + 1
- // last element only for slope calculation
- double step = (max - min) / (num - 1);
- double half_step = step / 2.0;
- for (int i = 0; i < num - 1; i++) {
- double sample_val = TfLiteRound(func(min + i * step) * 32768.0);
- double midpoint_interp_val =
- TfLiteRound((func(min + (i + 1) * step) * 32768.0 +
- TfLiteRound(func(min + i * step) * 32768.0)) /
- 2.0);
- double midpoint_val =
- TfLiteRound(func(min + i * step + half_step) * 32768.0);
- double midpoint_err = midpoint_interp_val - midpoint_val;
- double bias = TfLiteRound(midpoint_err / 2.0);
- table[i] = std::min(std::max(sample_val - bias, -32768.0), 32767.0);
- }
- table[num - 1] =
- std::min(std::max(TfLiteRound(func(max) * 32768.0), -32768.0), 32767.0);
-}
-
-// int16_t func table lookup, e.g., lookup exp() and 1/(1+x) used in softmax
-inline int16_t generic_int16_table_lookup(int16_t value, const int16_t* lut) {
- // 512 base value, lut[513] only for calculate slope
- uint16_t index = static_cast(256 + (value >> 7));
- assert(index < 512 && "LUT index out of range.");
- int16_t offset = value & 0x7f;
-
- // base and slope are Q0.15
- int16_t base = lut[index];
- int16_t slope = lut[index + 1] - lut[index];
-
- // Q0.15 * Q0.7 = Q0.22
- // Round and convert from Q0.22 to Q0.15
- int32_t delta = (static_cast(slope) * offset + 64) >> 7;
-
- // Q0.15 + Q0.15
- return base + delta;
-}
-
-// Table of sigmoid(i/24) at 0.16 format - 256 elements.
-
-// We use combined sigmoid and tanh look-up table, since
-// tanh(x) = 2*sigmoid(2*x) -1.
-// Both functions are symmetric, so the LUT table is only needed
-// for the absolute value of the input.
-static const uint16_t sigmoid_table_uint16[256] = {
- 32768, 33451, 34133, 34813, 35493, 36169, 36843, 37513, 38180, 38841, 39498,
- 40149, 40794, 41432, 42064, 42688, 43304, 43912, 44511, 45102, 45683, 46255,
- 46817, 47369, 47911, 48443, 48964, 49475, 49975, 50464, 50942, 51409, 51865,
- 52311, 52745, 53169, 53581, 53983, 54374, 54755, 55125, 55485, 55834, 56174,
- 56503, 56823, 57133, 57433, 57724, 58007, 58280, 58544, 58800, 59048, 59288,
- 59519, 59743, 59959, 60168, 60370, 60565, 60753, 60935, 61110, 61279, 61441,
- 61599, 61750, 61896, 62036, 62172, 62302, 62428, 62549, 62666, 62778, 62886,
- 62990, 63090, 63186, 63279, 63368, 63454, 63536, 63615, 63691, 63765, 63835,
- 63903, 63968, 64030, 64090, 64148, 64204, 64257, 64308, 64357, 64405, 64450,
- 64494, 64536, 64576, 64614, 64652, 64687, 64721, 64754, 64786, 64816, 64845,
- 64873, 64900, 64926, 64950, 64974, 64997, 65019, 65039, 65060, 65079, 65097,
- 65115, 65132, 65149, 65164, 65179, 65194, 65208, 65221, 65234, 65246, 65258,
- 65269, 65280, 65291, 65301, 65310, 65319, 65328, 65337, 65345, 65352, 65360,
- 65367, 65374, 65381, 65387, 65393, 65399, 65404, 65410, 65415, 65420, 65425,
- 65429, 65433, 65438, 65442, 65445, 65449, 65453, 65456, 65459, 65462, 65465,
- 65468, 65471, 65474, 65476, 65479, 65481, 65483, 65485, 65488, 65489, 65491,
- 65493, 65495, 65497, 65498, 65500, 65501, 65503, 65504, 65505, 65507, 65508,
- 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65517, 65518,
- 65519, 65520, 65520, 65521, 65522, 65522, 65523, 65523, 65524, 65524, 65525,
- 65525, 65526, 65526, 65526, 65527, 65527, 65528, 65528, 65528, 65529, 65529,
- 65529, 65529, 65530, 65530, 65530, 65530, 65531, 65531, 65531, 65531, 65531,
- 65532, 65532, 65532, 65532, 65532, 65532, 65533, 65533, 65533, 65533, 65533,
- 65533, 65533, 65533, 65534, 65534, 65534, 65534, 65534, 65534, 65534, 65534,
- 65534, 65534, 65535};
-
-// TODO(b/77858996): Add these to gemmlowp.
-template
-IntegerType SaturatingAddNonGemmlowp(IntegerType a, IntegerType b) {
- static_assert(std::is_same::value, "unimplemented");
- return a;
-}
-
-template <>
-inline std::int32_t SaturatingAddNonGemmlowp(std::int32_t a, std::int32_t b) {
- std::int64_t a64 = a;
- std::int64_t b64 = b;
- std::int64_t sum = a64 + b64;
- return static_cast(std::min(
- static_cast(std::numeric_limits::max()),
- std::max(
- static_cast(std::numeric_limits::min()),
- sum)));
-}
-
-template
-gemmlowp::FixedPoint SaturatingAddNonGemmlowp(
- gemmlowp::FixedPoint a,
- gemmlowp::FixedPoint b) {
- return gemmlowp::FixedPoint::FromRaw(
- SaturatingAddNonGemmlowp(a.raw(), b.raw()));
-}
-
-template
-IntegerType SaturatingSub(IntegerType a, IntegerType b) {
- static_assert(std::is_same::value, "unimplemented");
- return a;
-}
-
-template <>
-inline std::int16_t SaturatingSub(std::int16_t a, std::int16_t b) {
- std::int32_t a32 = a;
- std::int32_t b32 = b;
- std::int32_t diff = a32 - b32;
- return static_cast(
- std::min(static_cast(32767),
- std::max(static_cast(-32768), diff)));
-}
-
-template <>
-inline std::int32_t SaturatingSub(std::int32_t a, std::int32_t b) {
- std::int64_t a64 = a;
- std::int64_t b64 = b;
- std::int64_t diff = a64 - b64;
- return static_cast(std::min(
- static_cast(std::numeric_limits::max()),
- std::max(
- static_cast(std::numeric_limits::min()),
- diff)));
-}
-
-template
-gemmlowp::FixedPoint SaturatingSub(
- gemmlowp::FixedPoint a,
- gemmlowp::FixedPoint b) {
- return gemmlowp::FixedPoint::FromRaw(
- SaturatingSub(a.raw(), b.raw()));
-}
-// End section to be moved to gemmlowp.
-
-template
-IntegerType SaturatingRoundingMultiplyByPOTParam(IntegerType x, int exponent) {
- if (exponent == 0) {
- return x;
- }
- using ScalarIntegerType =
- typename gemmlowp::FixedPointRawTypeTraits::ScalarRawType;
- const IntegerType min =
- gemmlowp::Dup(std::numeric_limits::min());
- const IntegerType max =
- gemmlowp::Dup(std::numeric_limits::max());
- const int ScalarIntegerTypeBits = 8 * sizeof(ScalarIntegerType);
-
- const std::int32_t threshold =
- ((1 << (ScalarIntegerTypeBits - 1 - exponent)) - 1);
- const IntegerType positive_mask =
- gemmlowp::MaskIfGreaterThan(x, gemmlowp::Dup(threshold));
- const IntegerType negative_mask =
- gemmlowp::MaskIfLessThan(x, gemmlowp::Dup(-threshold));
-
- IntegerType result = gemmlowp::ShiftLeft(x, exponent);
- result = gemmlowp::SelectUsingMask(positive_mask, max, result);
- result = gemmlowp::SelectUsingMask(negative_mask, min, result);
- return result;
-}
-
-// If we want to leave IntegerBits fixed, then multiplication
-// by a power of two has to be saturating/rounding, not exact anymore.
-template
-gemmlowp::FixedPoint
-SaturatingRoundingMultiplyByPOTParam(
- gemmlowp::FixedPoint a, int exponent) {
- return gemmlowp::FixedPoint::FromRaw(
- SaturatingRoundingMultiplyByPOTParam(a.raw(), exponent));
-}
-
-// Convert int32_t multiplier to int16_t with rounding.
-inline void DownScaleInt32ToInt16Multiplier(int32_t multiplier_int32_t,
- int16_t* multiplier_int16_t) {
- TFLITE_DCHECK_GE(multiplier_int32_t, 0);
- static constexpr int32_t kRoundingOffset = 1 << 15;
- if (multiplier_int32_t >=
- std::numeric_limits::max() - kRoundingOffset) {
- *multiplier_int16_t = std::numeric_limits::max();
- return;
- }
- const int32_t result = (multiplier_int32_t + kRoundingOffset) >> 16;
- TFLITE_DCHECK_LE(result << 16, multiplier_int32_t + kRoundingOffset);
- TFLITE_DCHECK_GT(result << 16, multiplier_int32_t - kRoundingOffset);
- *multiplier_int16_t = result;
- TFLITE_DCHECK_EQ(*multiplier_int16_t, result);
-}
-
-// Minimum output bits to accommodate log of maximum input range. It actually
-// does not matter if one considers, say, [-64,64] or [-64,64).
-//
-// For example, run this through Octave:
-// [0:127; ...
-// ceil(log(abs( log(2.^(0:127))+1 ))/log(2)); ...
-// ceil(log(abs( log(2.^(0:127))+1 ))/log(2))]
-constexpr int min_log_x_output_bits(int input_bits) {
- return input_bits > 90 ? 7
- : input_bits > 44 ? 6
- : input_bits > 21 ? 5
- : input_bits > 10 ? 4
- : input_bits > 4 ? 3
- : input_bits > 1 ? 2
- : 1;
-}
-
-// Although currently the name of this function says that it cannot handle
-// values less than 1, in practice it can handle as low as 1/x_max, where
-// x_max is the largest representable input. In other words, the output range
-// is symmetric.
-template
-inline gemmlowp::FixedPoint
-log_x_for_x_greater_than_or_equal_to_1_impl(
- gemmlowp::FixedPoint input_val) {
- // assert(__builtin_clz(0u) >= std::numeric_limits::digits - 1);
- // assert(__builtin_clz(0u) <= std::numeric_limits::digits);
- using FixedPoint0 = gemmlowp::FixedPoint;
- // The reason for accumulating the result with an extra bit of headroom is
- // that z_pow_2_adj * log_2 might be saturated, and adding num_scaled *
- // recip_denom will otherwise introduce an error.
- static constexpr int kAccumIntegerBits = OutputIntegerBits + 1;
- using FixedPointAccum = gemmlowp::FixedPoint;
-
- const FixedPoint0 log_2 = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(
- FixedPoint0, 1488522236, std::log(2.0));
- const FixedPoint0 sqrt_sqrt_half = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(
- FixedPoint0, 1805811301, std::sqrt(std::sqrt(0.5)));
- const FixedPoint0 sqrt_half = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(
- FixedPoint0, 1518500250, std::sqrt(0.5));
- const FixedPoint0 one_quarter =
- GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(FixedPoint0, 536870912, 1.0 / 4.0);
-
- const FixedPoint0 alpha_n = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(
- FixedPoint0, 117049297, 11.0 / 240.0 * std::sqrt(std::sqrt(2.0)));
- const FixedPoint0 alpha_d = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(
- FixedPoint0, 127690142, 1.0 / 20.0 * std::sqrt(std::sqrt(2.0)));
- const FixedPoint0 alpha_i = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(
- FixedPoint0, 1057819769,
- 2.0 / std::sqrt(std::sqrt(2.0)) - std::sqrt(std::sqrt(2.0)));
- const FixedPoint0 alpha_f = GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(
- FixedPoint0, 638450708, 1.0 / 4.0 * std::sqrt(std::sqrt(2.0)));
-
- const FixedPointAccum shifted_quarter =
- gemmlowp::Rescale(one_quarter);
-
- // Reinterpret the input value as Q0.31, because we will figure out the
- // required shift "ourselves" instead of using, say, Rescale.
- FixedPoint0 z_a = FixedPoint0::FromRaw(input_val.raw());
- // z_a_pow_2 = input_integer_bits - z_a_headroom;
- int z_a_headroom_plus_1 = CountLeadingZeros(static_cast(z_a.raw()));
- FixedPoint0 r_a_tmp =
- SaturatingRoundingMultiplyByPOTParam(z_a, (z_a_headroom_plus_1 - 1));
- const int32_t r_a_raw =
- SaturatingRoundingMultiplyByPOTParam((r_a_tmp * sqrt_half).raw(), 1);
- // z_pow_2_adj = max(z_pow_2_a - 0.75, z_pow_2_b - 0.25);
- // z_pow_2_adj = max(InputIntegerBits - z_a_headroom_plus_1 + 0.25,
- // InputIntegerBits - z_b_headroom - 0.25);
- const FixedPointAccum z_a_pow_2_adj = SaturatingAddNonGemmlowp(
- FixedPointAccum::FromRaw(SaturatingRoundingMultiplyByPOTParam(
- InputIntegerBits - z_a_headroom_plus_1, 31 - kAccumIntegerBits)),
- shifted_quarter);
-
- // z_b is treated like z_a, but premultiplying by sqrt(0.5).
- FixedPoint0 z_b = z_a * sqrt_half;
- int z_b_headroom = CountLeadingZeros(static_cast(z_b.raw())) - 1;
- const int32_t r_b_raw =
- SaturatingRoundingMultiplyByPOTParam(z_a.raw(), z_b_headroom);
- const FixedPointAccum z_b_pow_2_adj = SaturatingSub(
- FixedPointAccum::FromRaw(SaturatingRoundingMultiplyByPOTParam(
- InputIntegerBits - z_b_headroom, 31 - kAccumIntegerBits)),
- shifted_quarter);
-
- const FixedPoint0 r = FixedPoint0::FromRaw(std::min(r_a_raw, r_b_raw));
- const FixedPointAccum z_pow_2_adj = FixedPointAccum::FromRaw(
- std::max(z_a_pow_2_adj.raw(), z_b_pow_2_adj.raw()));
-
- const FixedPoint0 p = gemmlowp::RoundingHalfSum(r, sqrt_sqrt_half);
- FixedPoint0 q = r - sqrt_sqrt_half;
- q = q + q;
-
- const FixedPoint0 common_sq = q * q;
- const FixedPoint0 num = q * r + q * common_sq * alpha_n;
- const FixedPoint0 denom_minus_one_0 =
- p * (alpha_i + q + alpha_d * common_sq) + alpha_f * q;
- const FixedPoint0 recip_denom =
- one_over_one_plus_x_for_x_in_0_1(denom_minus_one_0);
-
- const FixedPointAccum num_scaled = gemmlowp::Rescale(num);
- return gemmlowp::Rescale(z_pow_2_adj * log_2 +
- num_scaled * recip_denom);
-}
-
-template
-inline gemmlowp::FixedPoint
-log_x_for_x_greater_than_or_equal_to_1(
- gemmlowp::FixedPoint input_val) {
- static_assert(
- OutputIntegerBits >= min_log_x_output_bits(InputIntegerBits),
- "Output integer bits must be sufficient to accommodate logs of inputs.");
- return log_x_for_x_greater_than_or_equal_to_1_impl(
- input_val);
-}
-
-inline int32_t GetReciprocal(int32_t x, int x_integer_digits,
- int* num_bits_over_unit) {
- int headroom_plus_one = CountLeadingZeros(static_cast(x));
- // This is the number of bits to the left of the binary point above 1.0.
- // Consider x=1.25. In that case shifted_scale=0.8 and
- // no later adjustment will be needed.
- *num_bits_over_unit = x_integer_digits - headroom_plus_one;
- const int32_t shifted_sum_minus_one =
- static_cast((static_cast(x) << headroom_plus_one) -
- (static_cast(1) << 31));
-
- gemmlowp::FixedPoint shifted_scale =
- gemmlowp::one_over_one_plus_x_for_x_in_0_1(
- gemmlowp::FixedPoint::FromRaw(shifted_sum_minus_one));
- return shifted_scale.raw();
-}
-
-inline void GetInvSqrtQuantizedMultiplierExp(int32_t input, int reverse_shift,
- int32_t* output_inv_sqrt,
- int* output_shift) {
- TFLITE_DCHECK_GE(input, 0);
- if (input <= 1) {
- // Handle the input value 1 separately to avoid overflow in that case
- // in the general computation below (b/143972021). Also handle 0 as if it
- // were a 1. 0 is an invalid input here (divide by zero) and 1 is a valid
- // but rare/unrealistic input value. We can expect both to occur in some
- // incompletely trained models, but probably not in fully trained models.
- *output_inv_sqrt = std::numeric_limits::max();
- *output_shift = 0;
- return;
- }
- TFLITE_DCHECK_GT(input, 1);
- *output_shift = 11;
- while (input >= (1 << 29)) {
- input /= 4;
- ++*output_shift;
- }
- const unsigned max_left_shift_bits =
- CountLeadingZeros(static_cast(input)) - 1;
- const unsigned max_left_shift_bit_pairs = max_left_shift_bits / 2;
- const unsigned left_shift_bit_pairs = max_left_shift_bit_pairs - 1;
- *output_shift -= left_shift_bit_pairs;
- input <<= 2 * left_shift_bit_pairs;
- TFLITE_DCHECK_GE(input, (1 << 27));
- TFLITE_DCHECK_LT(input, (1 << 29));
- using gemmlowp::FixedPoint;
- using gemmlowp::Rescale;
- using gemmlowp::SaturatingRoundingMultiplyByPOT;
- // Using 3 integer bits gives us enough room for the internal arithmetic in
- // this Newton-Raphson iteration.
- using F3 = FixedPoint;
- using F0 = FixedPoint;
- const F3 fixedpoint_input = F3::FromRaw(input >> 1);
- const F3 fixedpoint_half_input =
- SaturatingRoundingMultiplyByPOT<-1>(fixedpoint_input);
- const F3 fixedpoint_half_three =
- GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(F3, (1 << 28) + (1 << 27), 1.5);
- // Newton-Raphson iteration
- // Naive unoptimized starting guess: x = 1
- F3 x = F3::One();
- // Naive unoptimized number of iterations: 5
- for (int i = 0; i < 5; i++) {
- const F3 x3 = Rescale<3>(x * x * x);
- x = Rescale<3>(fixedpoint_half_three * x - fixedpoint_half_input * x3);
- }
- const F0 fixedpoint_half_sqrt_2 =
- GEMMLOWP_CHECKED_FIXEDPOINT_CONSTANT(F0, 1518500250, std::sqrt(2.) / 2.);
- x = x * fixedpoint_half_sqrt_2;
- *output_inv_sqrt = x.raw();
- if (*output_shift < 0) {
- *output_inv_sqrt <<= -*output_shift;
- *output_shift = 0;
- }
- // Convert right shift (right is positive) to left shift.
- *output_shift *= reverse_shift;
-}
-
-// DO NOT USE THIS STRUCT FOR NEW FUNCTIONALITY BEYOND IMPLEMENTING
-// BROADCASTING.
-//
-// NdArrayDesc describes the shape and memory layout of an N-dimensional
-// rectangular array of numbers.
-//
-// NdArrayDesc is basically identical to Dims defined in types.h.
-// However, as Dims is to be deprecated, this class exists as an adaptor
-// to enable simple unoptimized implementations of element-wise broadcasting
-// operations.
-template
-struct NdArrayDesc {
- // The "extent" of each dimension. Indices along dimension d must be in the
- // half-open interval [0, extents[d]).
- int extents[N];
-
- // The number of *elements* (not bytes) between consecutive indices of each
- // dimension.
- int strides[N];
-};
-
-// DO NOT USE THIS FUNCTION FOR NEW FUNCTIONALITY BEYOND IMPLEMENTING
-// BROADCASTING.
-//
-// Same as Offset(), except takes as NdArrayDesc instead of Dims.
-inline int SubscriptToIndex(const NdArrayDesc<4>& desc, int i0, int i1, int i2,
- int i3) {
- TFLITE_DCHECK(i0 >= 0 && i0 < desc.extents[0]);
- TFLITE_DCHECK(i1 >= 0 && i1 < desc.extents[1]);
- TFLITE_DCHECK(i2 >= 0 && i2 < desc.extents[2]);
- TFLITE_DCHECK(i3 >= 0 && i3 < desc.extents[3]);
- return i0 * desc.strides[0] + i1 * desc.strides[1] + i2 * desc.strides[2] +
- i3 * desc.strides[3];
-}
-
-inline int SubscriptToIndex(const NdArrayDesc<5>& desc, int indexes[5]) {
- return indexes[0] * desc.strides[0] + indexes[1] * desc.strides[1] +
- indexes[2] * desc.strides[2] + indexes[3] * desc.strides[3] +
- indexes[4] * desc.strides[4];
-}
-
-// Given the dimensions of the operands for an element-wise binary broadcast,
-// adjusts them so that they can be directly iterated over with simple loops.
-// Returns the adjusted dims as instances of NdArrayDesc in 'desc0_out' and
-// 'desc1_out'. 'desc0_out' and 'desc1_out' cannot be nullptr.
-//
-// This function assumes that the two input shapes are compatible up to
-// broadcasting and the shorter one has already been prepended with 1s to be the
-// same length. E.g., if shape0 is (1, 16, 16, 64) and shape1 is (1, 64),
-// shape1 must already have been prepended to be (1, 1, 1, 64). Recall that
-// Dims refer to shapes in reverse order. In this case, input0_dims will be
-// (64, 16, 16, 1) and input1_dims will be (64, 1, 1, 1).
-//
-// When two shapes are compatible up to broadcasting, for each dimension d,
-// the input extents are either equal, or one of them is 1.
-//
-// This function performs the following for each dimension d:
-// - If the extents are equal, then do nothing since the loop that walks over
-// both of the input arrays is correct.
-// - Otherwise, one (and only one) of the extents must be 1. Say extent0 is 1
-// and extent1 is e1. Then set extent0 to e1 and stride0 *to 0*. This allows
-// array0 to be referenced *at any index* in dimension d and still access the
-// same slice.
-template
-inline void NdArrayDescsForElementwiseBroadcast(const Dims& input0_dims,
- const Dims& input1_dims,
- NdArrayDesc* desc0_out,
- NdArrayDesc* desc1_out) {
- TFLITE_DCHECK(desc0_out != nullptr);
- TFLITE_DCHECK(desc1_out != nullptr);
-
- // Copy dims to desc.
- for (int i = 0; i < N; ++i) {
- desc0_out->extents[i] = input0_dims.sizes[i];
- desc0_out->strides[i] = input0_dims.strides[i];
- desc1_out->extents[i] = input1_dims.sizes[i];
- desc1_out->strides[i] = input1_dims.strides[i];
- }
-
- // Walk over each dimension. If the extents are equal do nothing.
- // Otherwise, set the desc with extent 1 to have extent equal to the other and
- // stride 0.
- for (int i = 0; i < N; ++i) {
- const int extent0 = ArraySize(input0_dims, i);
- const int extent1 = ArraySize(input1_dims, i);
- if (extent0 != extent1) {
- if (extent0 == 1) {
- desc0_out->strides[i] = 0;
- desc0_out->extents[i] = extent1;
- } else {
- TFLITE_DCHECK_EQ(extent1, 1);
- desc1_out->strides[i] = 0;
- desc1_out->extents[i] = extent0;
- }
- }
- }
-}
-
-// Copies dims to desc, calculating strides.
-template
-inline void CopyDimsToDesc(const RuntimeShape& input_shape,
- NdArrayDesc* desc_out) {
- int desc_stride = 1;
- for (int i = N - 1; i >= 0; --i) {
- desc_out->extents[i] = input_shape.Dims(i);
- desc_out->strides[i] = desc_stride;
- desc_stride *= input_shape.Dims(i);
- }
-}
-
-template
-inline void NdArrayDescsForElementwiseBroadcast(
- const RuntimeShape& input0_shape, const RuntimeShape& input1_shape,
- NdArrayDesc* desc0_out, NdArrayDesc* desc1_out) {
- TFLITE_DCHECK(desc0_out != nullptr);
- TFLITE_DCHECK(desc1_out != nullptr);
-
- auto extended_input0_shape = RuntimeShape::ExtendedShape(N, input0_shape);
- auto extended_input1_shape = RuntimeShape::ExtendedShape(N, input1_shape);
-
- // Copy dims to desc, calculating strides.
- CopyDimsToDesc(extended_input0_shape, desc0_out);
- CopyDimsToDesc(extended_input1_shape, desc1_out);
-
- // Walk over each dimension. If the extents are equal do nothing.
- // Otherwise, set the desc with extent 1 to have extent equal to the other and
- // stride 0.
- for (int i = 0; i < N; ++i) {
- const int extent0 = extended_input0_shape.Dims(i);
- const int extent1 = extended_input1_shape.Dims(i);
- if (extent0 != extent1) {
- if (extent0 == 1) {
- desc0_out->strides[i] = 0;
- desc0_out->extents[i] = extent1;
- } else {
- TFLITE_DCHECK_EQ(extent1, 1);
- desc1_out->strides[i] = 0;
- desc1_out->extents[i] = extent0;
- }
- }
- }
-}
-
-template
-inline void NdArrayDescsForElementwiseBroadcast(
- const RuntimeShape& input0_shape, const RuntimeShape& input1_shape,
- const RuntimeShape& input2_shape, NdArrayDesc* desc0_out,
- NdArrayDesc* desc1_out, NdArrayDesc* desc2_out) {
- TFLITE_DCHECK(desc0_out != nullptr);
- TFLITE_DCHECK(desc1_out != nullptr);
- TFLITE_DCHECK(desc2_out != nullptr);
-
- auto extended_input0_shape = RuntimeShape::ExtendedShape(N, input0_shape);
- auto extended_input1_shape = RuntimeShape::ExtendedShape(N, input1_shape);
- auto extended_input2_shape = RuntimeShape::ExtendedShape(N, input2_shape);
-
- // Copy dims to desc, calculating strides.
- CopyDimsToDesc(extended_input0_shape, desc0_out);
- CopyDimsToDesc(extended_input1_shape, desc1_out);
- CopyDimsToDesc(extended_input2_shape, desc2_out);
-
- // Walk over each dimension. If the extents are equal do nothing.
- // Otherwise, set the desc with extent 1 to have extent equal to the other and
- // stride 0.
- for (int i = 0; i < N; ++i) {
- const int extent0 = extended_input0_shape.Dims(i);
- const int extent1 = extended_input1_shape.Dims(i);
- const int extent2 = extended_input2_shape.Dims(i);
-
- int extent = extent0;
- if (extent1 != 1) extent = extent1;
- if (extent2 != 1) extent = extent2;
-
- TFLITE_DCHECK(extent0 == 1 || extent0 == extent);
- TFLITE_DCHECK(extent1 == 1 || extent1 == extent);
- TFLITE_DCHECK(extent2 == 1 || extent2 == extent);
-
- if (!(extent0 == extent1 && extent1 == extent2)) {
- if (extent0 == 1) {
- desc0_out->strides[i] = 0;
- desc0_out->extents[i] = extent;
- }
- if (extent1 == 1) {
- desc1_out->strides[i] = 0;
- desc1_out->extents[i] = extent;
- }
- if (extent2 == 1) {
- desc2_out->strides[i] = 0;
- desc2_out->extents[i] = extent;
- }
- }
- }
-}
-
-// Detailed implementation of NDOpsHelper, the indexes must be a zero array.
-// This implementation is equivalent to N nested loops. Ex, if N=4, it can be
-// re-writen as:
-// for (int b = 0; b < output.extents[0]; ++b) {
-// for (int y = 0; y < output.extents[1]; ++y) {
-// for (int x = 0; x < output.extents[2]; ++x) {
-// for (int c = 0; c < output.extents[3]; ++c) {
-// calc({b,y,x,c});
-// }
-// }
-// }
-// }
-template
-typename std::enable_if::type NDOpsHelperImpl(
- const NdArrayDesc& output, const Calc& calc, int indexes[N]) {
- for (indexes[DIM] = 0; indexes[DIM] < output.extents[DIM]; ++indexes[DIM]) {
- NDOpsHelperImpl(output, calc, indexes);
- }
-}
-
-template
-typename std::enable_if::type NDOpsHelperImpl(
- const NdArrayDesc& output, const Calc& calc, int indexes[N]) {
- for (indexes[DIM] = 0; indexes[DIM] < output.extents[DIM]; ++indexes[DIM]) {
- calc(indexes);
- }
-}
-
-// Execute the calc function in the innermost iteration based on the shape of
-// the output. The calc function should take a single argument of type int[N].
-template
-inline void NDOpsHelper(const NdArrayDesc& output, const Calc& calc) {
- int indexes[N] = {0};
- NDOpsHelperImpl(output, calc, indexes);
-}
-// Copied from gemmlowp::RoundDown when we dropped direct dependency on
-// gemmlowp.
-//
-// Returns the runtime argument rounded down to the nearest multiple of
-// the fixed Modulus.
-template
-Integer RoundDown(Integer i) {
- return i - (i % Modulus);
-}
-
-// Copied from gemmlowp::RoundUp when we dropped direct dependency on
-// gemmlowp.
-//
-// Returns the runtime argument rounded up to the nearest multiple of
-// the fixed Modulus.
-template
-Integer RoundUp(Integer i) {
- return RoundDown(i + Modulus - 1);
-}
-
-// Copied from gemmlowp::CeilQuotient when we dropped direct dependency on
-// gemmlowp.
-//
-// Returns the quotient a / b rounded up ('ceil') to the nearest integer.
-template
-Integer CeilQuotient(Integer a, Integer b) {
- return (a + b - 1) / b;
-}
-
-// This function is a copy of gemmlowp::HowManyThreads, copied when we dropped
-// the direct dependency of internal/optimized/ on gemmlowp.
-//
-// It computes a reasonable number of threads to use for a GEMM of shape
-// (rows, cols, depth).
-//
-// TODO(b/131910176): get rid of this function by switching each call site
-// to its own more sensible logic for its own workload.
-template
-inline int LegacyHowManyThreads(int max_num_threads, int rows, int cols,
- int depth) {
- // Early-exit in the default case where multi-threading is disabled.
- if (max_num_threads == 1) {
- return 1;
- }
-
- // Ensure that each thread has KernelRows rows to process, if at all possible.
- int thread_count = std::min(max_num_threads, rows / KernelRows);
-
- // Limit the number of threads according to the overall size of the problem.
- if (thread_count > 1) {
- // Empirically determined value.
- static constexpr std::uint64_t min_cubic_size_per_thread = 64 * 1024;
-
- // We can only multiply two out of three sizes without risking overflow
- const std::uint64_t cubic_size =
- std::uint64_t(rows) * std::uint64_t(cols) * std::uint64_t(depth);
-
- thread_count = std::min(
- thread_count, static_cast(cubic_size / min_cubic_size_per_thread));
- }
-
- if (thread_count < 1) {
- thread_count = 1;
- }
-
- assert(thread_count > 0 && thread_count <= max_num_threads);
- return thread_count;
-}
-
-template
-void optimized_ops_preload_l1_stream(const T* ptr) {
-#ifdef __GNUC__
- // builtin offered by GCC-compatible compilers including clang
- __builtin_prefetch(ptr, /* 0 means read */ 0, /* 0 means no locality */ 0);
-#else
- (void)ptr;
-#endif
-}
-
-template
-void optimized_ops_preload_l1_keep(const T* ptr) {
-#ifdef __GNUC__
- // builtin offered by GCC-compatible compilers including clang
- __builtin_prefetch(ptr, /* 0 means read */ 0, /* 3 means high locality */ 3);
-#else
- (void)ptr;
-#endif
-}
-
-template
-void optimized_ops_prefetch_write_l1_keep(const T* ptr) {
-#ifdef __GNUC__
- // builtin offered by GCC-compatible compilers including clang
- __builtin_prefetch(ptr, /* 1 means write */ 1, /* 3 means high locality */ 3);
-#else
- (void)ptr;
-#endif
-}
-
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_COMMON_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/compatibility.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/compatibility.h
deleted file mode 100644
index 61becad30c5c2277f896d4b90ced998068c72363..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/compatibility.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/* Copyright 2017 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_COMPATIBILITY_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_COMPATIBILITY_H_
-
-#include
-
-#include "tensorflow/lite/kernels/op_macros.h"
-
-#ifndef TFLITE_DCHECK
-#define TFLITE_DCHECK(condition) (condition) ? (void)0 : TFLITE_ASSERT_FALSE
-#endif
-
-#ifndef TFLITE_DCHECK_EQ
-#define TFLITE_DCHECK_EQ(x, y) ((x) == (y)) ? (void)0 : TFLITE_ASSERT_FALSE
-#endif
-
-#ifndef TFLITE_DCHECK_NE
-#define TFLITE_DCHECK_NE(x, y) ((x) != (y)) ? (void)0 : TFLITE_ASSERT_FALSE
-#endif
-
-#ifndef TFLITE_DCHECK_GE
-#define TFLITE_DCHECK_GE(x, y) ((x) >= (y)) ? (void)0 : TFLITE_ASSERT_FALSE
-#endif
-
-#ifndef TFLITE_DCHECK_GT
-#define TFLITE_DCHECK_GT(x, y) ((x) > (y)) ? (void)0 : TFLITE_ASSERT_FALSE
-#endif
-
-#ifndef TFLITE_DCHECK_LE
-#define TFLITE_DCHECK_LE(x, y) ((x) <= (y)) ? (void)0 : TFLITE_ASSERT_FALSE
-#endif
-
-#ifndef TFLITE_DCHECK_LT
-#define TFLITE_DCHECK_LT(x, y) ((x) < (y)) ? (void)0 : TFLITE_ASSERT_FALSE
-#endif
-
-// TODO(ahentz): Clean up: We should stick to the DCHECK versions.
-#ifndef TFLITE_CHECK
-#define TFLITE_CHECK(condition) (condition) ? (void)0 : TFLITE_ABORT
-#endif
-
-#ifndef TFLITE_CHECK_EQ
-#define TFLITE_CHECK_EQ(x, y) ((x) == (y)) ? (void)0 : TFLITE_ABORT
-#endif
-
-#ifndef TFLITE_CHECK_NE
-#define TFLITE_CHECK_NE(x, y) ((x) != (y)) ? (void)0 : TFLITE_ABORT
-#endif
-
-#ifndef TFLITE_CHECK_GE
-#define TFLITE_CHECK_GE(x, y) ((x) >= (y)) ? (void)0 : TFLITE_ABORT
-#endif
-
-#ifndef TFLITE_CHECK_GT
-#define TFLITE_CHECK_GT(x, y) ((x) > (y)) ? (void)0 : TFLITE_ABORT
-#endif
-
-#ifndef TFLITE_CHECK_LE
-#define TFLITE_CHECK_LE(x, y) ((x) <= (y)) ? (void)0 : TFLITE_ABORT
-#endif
-
-#ifndef TFLITE_CHECK_LT
-#define TFLITE_CHECK_LT(x, y) ((x) < (y)) ? (void)0 : TFLITE_ABORT
-#endif
-
-#ifndef TF_LITE_STATIC_MEMORY
-// TODO(b/162019032): Consider removing these type-aliases.
-using int8 = std::int8_t;
-using uint8 = std::uint8_t;
-using int16 = std::int16_t;
-using uint16 = std::uint16_t;
-using int32 = std::int32_t;
-using uint32 = std::uint32_t;
-#endif // !defined(TF_LITE_STATIC_MEMORY)
-
-// TFLITE_DEPRECATED()
-//
-// Duplicated from absl/base/macros.h to avoid pulling in that library.
-// Marks a deprecated class, struct, enum, function, method and variable
-// declarations. The macro argument is used as a custom diagnostic message (e.g.
-// suggestion of a better alternative).
-//
-// Example:
-//
-// class TFLITE_DEPRECATED("Use Bar instead") Foo {...};
-// TFLITE_DEPRECATED("Use Baz instead") void Bar() {...}
-//
-// Every usage of a deprecated entity will trigger a warning when compiled with
-// clang's `-Wdeprecated-declarations` option. This option is turned off by
-// default, but the warnings will be reported by clang-tidy.
-#if defined(__clang__) && __cplusplus >= 201103L
-#define TFLITE_DEPRECATED(message) __attribute__((deprecated(message)))
-#endif
-
-#ifndef TFLITE_DEPRECATED
-#define TFLITE_DEPRECATED(message)
-#endif
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_COMPATIBILITY_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/cppmath.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/cppmath.h
deleted file mode 100644
index 24a3aec82e38ae20bd99b54f5167ec80489079ea..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/cppmath.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* Copyright 2020 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_CPPMATH_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_CPPMATH_H_
-
-#include
-
-namespace tflite {
-
-#if defined(TF_LITE_USE_GLOBAL_CMATH_FUNCTIONS) || \
- (defined(__ANDROID__) && !defined(__NDK_MAJOR__)) || defined(ARDUINO) || \
- defined(__ZEPHYR__)
-#define TF_LITE_GLOBAL_STD_PREFIX
-#else
-#define TF_LITE_GLOBAL_STD_PREFIX std
-#endif
-
-#define DECLARE_STD_GLOBAL_SWITCH1(tf_name, std_name) \
- template \
- inline T tf_name(const T x) { \
- return TF_LITE_GLOBAL_STD_PREFIX::std_name(x); \
- }
-
-DECLARE_STD_GLOBAL_SWITCH1(TfLiteRound, round);
-
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_CPPMATH_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/max.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/max.h
deleted file mode 100644
index c18100272dbf21a5175f849c4e54337dab287a92..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/max.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright 2020 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_
-
-#include
-
-namespace tflite {
-
-#if defined(TF_LITE_USE_GLOBAL_MAX) || defined(__ZEPHYR__)
-inline float TfLiteMax(const float& x, const float& y) {
- return std::max(x, y);
-}
-#else
-template
-inline T TfLiteMax(const T& x, const T& y) {
- return std::fmax(x, y);
-}
-#endif
-
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/min.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/min.h
deleted file mode 100644
index 62035dccd89e59a028c9c5a27e5fdcc73344f759..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/min.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/* Copyright 2020 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_MIN_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_MIN_H_
-
-#include
-
-namespace tflite {
-
-#if defined(TF_LITE_USE_GLOBAL_MIN) || defined(__ZEPHYR__)
-inline float TfLiteMin(const float& x, const float& y) {
- return std::min(x, y);
-}
-#else
-template
-inline T TfLiteMin(const T& x, const T& y) {
- return std::fmin(x, y);
-}
-#endif
-
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_MIN_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/optimized/neon_check.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/optimized/neon_check.h
deleted file mode 100644
index bbf745ce1d12c7ad24d3f71d71b608ab706e91d4..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/optimized/neon_check.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_
-
-#if defined(__ARM_NEON__) || defined(__ARM_NEON)
-#define USE_NEON
-#include
-#endif
-
-#if defined __GNUC__ && defined __SSE4_1__ && !defined TF_LITE_DISABLE_X86_NEON
-#define USE_NEON
-#include "NEON_2_SSE.h"
-#endif
-
-// NEON_OR_PORTABLE(SomeFunc, args) calls NeonSomeFunc(args) if USE_NEON is
-// defined, PortableSomeFunc(args) otherwise.
-#ifdef USE_NEON
-// Always use Neon code
-#define NEON_OR_PORTABLE(funcname, ...) Neon##funcname(__VA_ARGS__)
-
-#else
-// No NEON available: Use Portable code
-#define NEON_OR_PORTABLE(funcname, ...) Portable##funcname(__VA_ARGS__)
-
-#endif // defined(USE_NEON)
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/quantization_util.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/quantization_util.h
deleted file mode 100644
index 0ee914b0689ed112d80ef758466e3d699e9bf78c..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/quantization_util.h
+++ /dev/null
@@ -1,292 +0,0 @@
-/* Copyright 2017 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_QUANTIZATION_UTIL_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_QUANTIZATION_UTIL_H_
-
-#include
-#include
-#include
-
-#include "tensorflow/lite/kernels/internal/compatibility.h"
-#include "tensorflow/lite/kernels/internal/cppmath.h"
-#include "tensorflow/lite/kernels/internal/types.h"
-
-namespace tflite {
-
-// Given the min and max values of a float array, return
-// reasonable quantization parameters to use for this array.
-template
-QuantizationParams ChooseQuantizationParams(double rmin, double rmax,
- bool narrow_range) {
- const T qmin = std::numeric_limits::min() + (narrow_range ? 1 : 0);
- const T qmax = std::numeric_limits::max();
- const double qmin_double = qmin;
- const double qmax_double = qmax;
- // 0 should always be a representable value. Let's assume that the initial
- // min,max range contains 0.
- TFLITE_CHECK_LE(rmin, 0.);
- TFLITE_CHECK_GE(rmax, 0.);
- if (rmin == rmax) {
- // Special case where the min,max range is a point. Should be {0}.
- TFLITE_CHECK_EQ(rmin, 0.);
- TFLITE_CHECK_EQ(rmax, 0.);
- QuantizationParams quantization_params;
- quantization_params.zero_point = 0;
- quantization_params.scale = 0.;
- return quantization_params;
- }
-
- // General case.
- //
- // First determine the scale.
- const double scale = (rmax - rmin) / (qmax_double - qmin_double);
-
- // Zero-point computation.
- // First the initial floating-point computation. The zero-point can be
- // determined from solving an affine equation for any known pair
- // (real value, corresponding quantized value).
- // We know two such pairs: (rmin, qmin) and (rmax, qmax).
- // The arithmetic error on the zero point computed from either pair
- // will be roughly machine_epsilon * (sum of absolute values of terms)
- // so we want to use the variant that adds the smaller terms.
- const double zero_point_from_min = qmin_double - rmin / scale;
- const double zero_point_from_max = qmax_double - rmax / scale;
- const double zero_point_from_min_error =
- std::abs(qmin_double) + std::abs(rmin / scale);
- const double zero_point_from_max_error =
- std::abs(qmax_double) + std::abs(rmax / scale);
-
- const double zero_point_double =
- zero_point_from_min_error < zero_point_from_max_error
- ? zero_point_from_min
- : zero_point_from_max;
-
- // Now we need to nudge the zero point to be an integer
- // (our zero points are integer, and this is motivated by the requirement
- // to be able to represent the real value "0" exactly as a quantized value,
- // which is required in multiple places, for example in Im2col with SAME
- // padding).
- T nudged_zero_point = 0;
- if (zero_point_double < qmin_double) {
- nudged_zero_point = qmin;
- } else if (zero_point_double > qmax_double) {
- nudged_zero_point = qmax;
- } else {
- nudged_zero_point = static_cast(round(zero_point_double));
- }
- // The zero point should always be in the range of quantized value,
- // [qmin, qmax].
- TFLITE_CHECK_GE(nudged_zero_point, qmin);
- TFLITE_CHECK_LE(nudged_zero_point, qmax);
-
- // Finally, store the result nudged quantization params.
- QuantizationParams quantization_params;
- quantization_params.zero_point = nudged_zero_point;
- quantization_params.scale = scale;
- return quantization_params;
-}
-
-template
-QuantizationParams ChooseQuantizationParams(double rmin, double rmax) {
- return ChooseQuantizationParams(rmin, rmax, false);
-}
-
-// Converts a floating-point number to an integer. For all inputs x where
-// static_cast(x) is legal according to the C++ standard, the result
-// is identical to that cast (i.e. the result is x with its fractional part
-// truncated whenever that is representable as IntOut).
-//
-// static_cast would cause undefined behavior for the following cases, which
-// have well-defined behavior for this function:
-//
-// 1. If x is NaN, the result is zero.
-//
-// 2. If the truncated form of x is above the representable range of IntOut,
-// the result is std::numeric_limits::max().
-//
-// 3. If the truncated form of x is below the representable range of IntOut,
-// the result is std::numeric_limits::min().
-//
-// Note that cases #2 and #3 cover infinities as well as finite numbers.
-//
-// The range of FloatIn must include the range of IntOut, otherwise
-// the results are undefined.
-// TODO(sfeuz): Replace by absl::SafeCast once available.
-template
-IntOut SafeCast(FloatIn x) {
- static_assert(!std::numeric_limits::is_integer,
- "FloatIn is integer");
- static_assert(std::numeric_limits::is_integer,
- "IntOut is not integer");
- static_assert(std::numeric_limits::radix == 2, "IntOut is base 2");
-
- // Special case NaN, for which the logic below doesn't work.
- if (std::isnan(x)) {
- return 0;
- }
-
- // Negative values all clip to zero for unsigned results.
- if (!std::numeric_limits::is_signed && x < 0) {
- return 0;
- }
-
- // Handle infinities.
- if (std::isinf(x)) {
- return x < 0 ? std::numeric_limits::min()
- : std::numeric_limits::max();
- }
-
- // Set exp such that x == f * 2^exp for some f with |f| in [0.5, 1.0),
- // unless x is zero in which case exp == 0. Note that this implies that the
- // magnitude of x is strictly less than 2^exp.
- int exp = 0;
- std::frexp(x, &exp);
-
- // Let N be the number of non-sign bits in the representation of IntOut. If
- // the magnitude of x is strictly less than 2^N, the truncated version of x
- // is representable as IntOut. The only representable integer for which this
- // is not the case is kMin for signed types (i.e. -2^N), but that is covered
- // by the fall-through below.
- if (exp <= std::numeric_limits::digits) {
- return x;
- }
-
- // Handle numbers with magnitude >= 2^N.
- return x < 0 ? std::numeric_limits::min()
- : std::numeric_limits::max();
-}
-
-// Decompose a double multiplier into a Q0.31 int32 representation of its
-// significand, and shift representation of NEGATIVE its exponent ---
-// this is intended as a RIGHT-shift.
-//
-// Restricted to the case where the multiplier < 1 (and non-negative).
-void QuantizeMultiplierSmallerThanOneExp(double double_multiplier,
- int32_t* quantized_multiplier,
- int* left_shift);
-
-// Decompose a double multiplier into a Q0.31 int32 representation of its
-// significand, and shift representation of its exponent.
-//
-// Restricted to the case where the multiplier > 1.
-void QuantizeMultiplierGreaterThanOne(double double_multiplier,
- int32_t* quantized_multiplier,
- int* left_shift);
-
-// Decompose a double multiplier into a Q0.31 int32 representation of its
-// significand, and shift representation of its exponent.
-//
-// Handles an arbitrary positive multiplier. The 'shift' output-value is
-// basically the 'floating-point exponent' of the multiplier:
-// Negative for a right-shift (when the multiplier is <1), positive for a
-// left-shift (when the multiplier is >1)
-void QuantizeMultiplier(double double_multiplier, int32_t* quantized_multiplier,
- int* shift);
-
-// Splits a double input value into a returned fraction, and a shift value from
-// the exponent, using only bitwise and integer operations to support
-// microcontrollers and other environments without floating-point support.
-//
-// This is designed to be a replacement for how std::frexp() is used within the
-// QuantizeMultiplier() function, and so has a different signature than the
-// standard version, returning a 64-bit integer rather than a double. This
-// result has a maximum value of 1<<31, with the fraction expressed as a
-// proportion of that maximum.
-//
-// std::frexp() returns NaNs and infinities unmodified, but since we're
-// returning integers that can't represent those values, instead we return
-// a shift of std::numeric_limits::max() for all bad numbers, with an int64
-// result of 0 for NaNs, std:numeric_limits::max() for +INFINITY, and
-// std::numeric_limits::min() for -INFINITY. Denormalized inputs will
-// result in return values that end up truncating some bits at the end,
-// reflecting the loss of precision inherent in denormalization.
-int64_t IntegerFrExp(double input, int* shift);
-
-// Converts an integer fraction in the format produced by IntegerFrExp (where
-// 0x40000000 is 1.0) and an exponent shift (between -1022 and +1022) into an
-// IEEE binary64 double format result. The implementation uses only integer and
-// bitwise operators, so no floating point hardware support or emulation is
-// needed. This is here so quantized operations can run non-time-critical
-// preparation calculations on microcontrollers and other platforms without
-// float support.
-double DoubleFromFractionAndShift(int64_t fraction, int shift);
-
-// Performs a multiplication of two numbers in double format, using only integer
-// and bitwise instructions. This is aimed at supporting housekeeping functions
-// for quantized operations on microcontrollers without floating-point hardware.
-double IntegerDoubleMultiply(double a, double b);
-
-// Returns -1 if a is less than b, 0 if a and b are equal, and +1 if a is
-// greater than b. It is implemented using only integer and logical instructions
-// so that it can be easily run on microcontrollers for quantized operations.
-int IntegerDoubleCompare(double a, double b);
-
-// This first creates a multiplier in a double equivalent of
-// Q(input_integer_bits).(31-input_integer_bits) representation, with extra
-// precision in the double's fractional bits. It then splits the result into
-// significand and exponent.
-void PreprocessSoftmaxScaling(double beta, double input_scale,
- int input_integer_bits,
- int32_t* quantized_multiplier, int* left_shift);
-// Like PreprocessSoftmaxScaling, but inverse scaling factors also calculated.
-void PreprocessLogSoftmaxScalingExp(double beta, double input_scale,
- int input_integer_bits,
- int32_t* quantized_multiplier,
- int* left_shift,
- int32_t* reverse_scaling_divisor,
- int* reverse_scaling_left_shift);
-// Calculate the largest input that will result in a within-bounds intermediate
-// result within MultiplyByQuantizedMultiplierGreaterThanOne. In other words,
-// it must not overflow before we reduce the value by multiplication by the
-// input multiplier. The negative radius is used as the minimum difference in
-// Softmax.
-int CalculateInputRadius(int input_integer_bits, int input_left_shift,
- int total_signed_bits = 31);
-
-// Nudges a min/max quantization range to ensure zero is zero.
-// Gymnastics with nudged zero point is to ensure that real zero maps to
-// an integer, which is required for e.g. zero-padding in convolutional layers.
-// Outputs nudged_min, nudged_max, nudged_scale.
-void NudgeQuantizationRange(const float min, const float max,
- const int quant_min, const int quant_max,
- float* nudged_min, float* nudged_max,
- float* nudged_scale);
-
-// Fake quantizes (quantizes and dequantizes) input_data using the scale,
-// nudged_min, and nudged_max from NudgeQuantizationRange. This matches the code
-// in TensorFlow's FakeQuantizeWithMinMaxVarsFunctor.
-void FakeQuantizeArray(const float nudged_scale, const float nudged_min,
- const float nudged_max, const float* input_data,
- float* output_data, const float size);
-
-// If x is approximately a power of two (with any positive or negative
-// exponent), stores that exponent (i.e. log2(x)) in *log2_result, otherwise
-// returns false.
-bool CheckedLog2(const float x, int* log2_result);
-
-// Decomposes an array of double multipliers into a Q0.31 int32 representation
-// of its significand, and shift representation of its exponent.
-//
-// Handles an arbitrary multiplier. The 'shift' output-value is
-// basically the 'floating-point exponent' of the multiplier:
-// Negative for a right-shift (when the multiplier is <1), positive for a
-// left-shift (when the multiplier is >1)
-void QuantizeMultiplierArray(const double* effective_scales, size_t size,
- int32_t* effective_scale_significand,
- int* effective_shift);
-
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_QUANTIZATION_UTIL_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/add.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/add.h
deleted file mode 100644
index 5be7ab4dc0c616f9ee288a7353b5d3ba6920323a..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/add.h
+++ /dev/null
@@ -1,454 +0,0 @@
-/* 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ADD_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ADD_H_
-
-#include "fixedpoint/fixedpoint.h"
-#include "tensorflow/lite/kernels/internal/common.h"
-
-namespace tflite {
-
-namespace reference_ops {
-
-template
-inline void Add(const ArithmeticParams& params,
- const RuntimeShape& input1_shape, const T* input1_data,
- const RuntimeShape& input2_shape, const T* input2_data,
- const RuntimeShape& output_shape, T* output_data) {
- const int flat_size =
- MatchingElementsSize(input1_shape, input2_shape, output_shape);
- for (int i = 0; i < flat_size; ++i) {
- output_data[i] = ActivationFunctionWithMinMax(
- input1_data[i] + input2_data[i], params.quantized_activation_min,
- params.quantized_activation_max);
- }
-}
-
-inline void Add(const ArithmeticParams& params,
- const RuntimeShape& input1_shape, const float* input1_data,
- const RuntimeShape& input2_shape, const float* input2_data,
- const RuntimeShape& output_shape, float* output_data) {
- const int flat_size =
- MatchingElementsSize(input1_shape, input2_shape, output_shape);
- for (int i = 0; i < flat_size; i++) {
- auto x = input1_data[i] + input2_data[i];
- output_data[i] = ActivationFunctionWithMinMax(
- x, params.float_activation_min, params.float_activation_max);
- }
-}
-
-// Element-wise add that can often be used for inner loop of broadcast add as
-// well as the non-broadcast add.
-
-// This function is used for 8-bit as well as for 16-bit, but the accumulator
-// is 32-bit for both cases. The overflow does not happen due to the
-// choice of the shift (20 or 15, accordingly - see add.cc for more comments).
-template
-inline void AddElementwise(int size, const ArithmeticParams& params,
- const T* input1_data, const T* input2_data,
- T* output_data) {
- TFLITE_DCHECK_GT(params.input1_offset, -std::numeric_limits::max());
- TFLITE_DCHECK_GT(params.input2_offset, -std::numeric_limits::max());
- TFLITE_DCHECK_LT(params.input1_offset, std::numeric_limits::max());
- TFLITE_DCHECK_LT(params.input2_offset, std::numeric_limits::max());
-
- for (int i = 0; i < size; ++i) {
- const int32_t input1_val = params.input1_offset + input1_data[i];
- const int32_t input2_val = params.input2_offset + input2_data[i];
- const int32_t shifted_input1_val = input1_val * (1 << params.left_shift);
- const int32_t shifted_input2_val = input2_val * (1 << params.left_shift);
- const int32_t scaled_input1_val =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- shifted_input1_val, params.input1_multiplier, params.input1_shift);
- const int32_t scaled_input2_val =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- shifted_input2_val, params.input2_multiplier, params.input2_shift);
- const int32_t raw_sum = scaled_input1_val + scaled_input2_val;
- const int32_t raw_output =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- raw_sum, params.output_multiplier, params.output_shift) +
- params.output_offset;
- const int32_t clamped_output =
- std::min(params.quantized_activation_max,
- std::max(params.quantized_activation_min, raw_output));
- output_data[i] = static_cast(clamped_output);
- }
-}
-
-// Scalar-broadcast add that can be used for inner loop of more general
-// broadcast add, so that, for example, scalar-broadcast with batch will still
-// be fast.
-inline void AddScalarBroadcast(int size, const ArithmeticParams& params,
- uint8_t input1_data, const uint8_t* input2_data,
- uint8_t* output_data) {
- TFLITE_DCHECK_GT(params.input1_offset, -256);
- TFLITE_DCHECK_GT(params.input2_offset, -256);
- TFLITE_DCHECK_LT(params.input1_offset, 256);
- TFLITE_DCHECK_LT(params.input2_offset, 256);
-
- const int32_t input1_val = params.input1_offset + input1_data;
- const int32_t shifted_input1_val = input1_val * (1 << params.left_shift);
- const int32_t scaled_input1_val =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- shifted_input1_val, params.input1_multiplier, params.input1_shift);
- for (int i = 0; i < size; ++i) {
- const int32_t input2_val = params.input2_offset + input2_data[i];
- const int32_t shifted_input2_val = input2_val * (1 << params.left_shift);
- const int32_t scaled_input2_val =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- shifted_input2_val, params.input2_multiplier, params.input2_shift);
- const int32_t raw_sum = scaled_input1_val + scaled_input2_val;
- const int32_t raw_output =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- raw_sum, params.output_multiplier, params.output_shift) +
- params.output_offset;
- const int32_t clamped_output =
- std::min(params.quantized_activation_max,
- std::max(params.quantized_activation_min, raw_output));
- output_data[i] = static_cast(clamped_output);
- }
-}
-
-inline void Add(const ArithmeticParams& params,
- const RuntimeShape& input1_shape, const uint8_t* input1_data,
- const RuntimeShape& input2_shape, const uint8_t* input2_data,
- const RuntimeShape& output_shape, uint8_t* output_data) {
- TFLITE_DCHECK_LE(params.quantized_activation_min,
- params.quantized_activation_max);
- const int flat_size =
- MatchingElementsSize(input1_shape, input2_shape, output_shape);
-
- TFLITE_DCHECK_GT(params.input1_offset, -256);
- TFLITE_DCHECK_GT(params.input2_offset, -256);
- TFLITE_DCHECK_LT(params.input1_offset, 256);
- TFLITE_DCHECK_LT(params.input2_offset, 256);
- AddElementwise(flat_size, params, input1_data, input2_data, output_data);
-}
-
-inline void AddGeneralParamScale(const ArithmeticParams& params,
- const RuntimeShape& input1_shape,
- const int16_t* input1_data,
- const RuntimeShape& input2_shape,
- const int16_t* input2_data,
- const RuntimeShape& output_shape,
- int16_t* output_data) {
- TFLITE_DCHECK_LE(params.quantized_activation_min,
- params.quantized_activation_max);
- const int flat_size =
- MatchingElementsSize(input1_shape, input2_shape, output_shape);
-
- int max_value = std::numeric_limits::max();
-
- TFLITE_DCHECK_GT(params.input1_offset, -max_value);
- TFLITE_DCHECK_GT(params.input2_offset, -max_value);
- TFLITE_DCHECK_LT(params.input1_offset, max_value);
- TFLITE_DCHECK_LT(params.input2_offset, max_value);
- AddElementwise(flat_size, params, input1_data, input2_data, output_data);
-}
-
-inline void Add(const ArithmeticParams& params,
- const RuntimeShape& input1_shape, const int16_t* input1_data,
- const RuntimeShape& input2_shape, const int16_t* input2_data,
- const RuntimeShape& output_shape, int16_t* output_data,
- bool pot_scale = true) {
- if (!pot_scale) {
- AddGeneralParamScale(params, input1_shape, input1_data, input2_shape,
- input2_data, output_shape, output_data);
- return;
- }
-
- TFLITE_DCHECK_LE(params.quantized_activation_min,
- params.quantized_activation_max);
-
- const int input1_shift = params.input1_shift;
- const int flat_size =
- MatchingElementsSize(input1_shape, input2_shape, output_shape);
- const int16_t output_activation_min = params.quantized_activation_min;
- const int16_t output_activation_max = params.quantized_activation_max;
-
- TFLITE_DCHECK(input1_shift == 0 || params.input2_shift == 0);
- TFLITE_DCHECK_LE(input1_shift, 0);
- TFLITE_DCHECK_LE(params.input2_shift, 0);
- const int16_t* not_shift_input =
- input1_shift == 0 ? input1_data : input2_data;
- const int16_t* shift_input = input1_shift == 0 ? input2_data : input1_data;
- const int input_right_shift =
- input1_shift == 0 ? -params.input2_shift : -input1_shift;
-
- for (int i = 0; i < flat_size; i++) {
- // F0 uses 0 integer bits, range [-1, 1].
- using F0 = gemmlowp::FixedPoint;
-
- F0 input_ready_scaled = F0::FromRaw(not_shift_input[i]);
- F0 scaled_input = F0::FromRaw(
- gemmlowp::RoundingDivideByPOT(shift_input[i], input_right_shift));
- F0 result = gemmlowp::SaturatingAdd(scaled_input, input_ready_scaled);
- const int16_t raw_output = result.raw();
- const int16_t clamped_output = std::min(
- output_activation_max, std::max(output_activation_min, raw_output));
- output_data[i] = clamped_output;
- }
-}
-
-// TODO(jiawen): We can implement BroadcastAdd on buffers of arbitrary
-// dimensionality if the runtime code does a single loop over one dimension
-// that handles broadcasting as the base case. The code generator would then
-// generate max(D1, D2) nested for loops.
-// TODO(benoitjacob): BroadcastAdd is intentionally duplicated from
-// reference_ops.h. Once an optimized version is implemented and NdArrayDesc
-// is no longer referenced in this file, move NdArrayDesc from types.h to
-// reference_ops.h.
-inline void BroadcastAdd4DSlow(const ArithmeticParams& params,
- const RuntimeShape& input1_shape,
- const float* input1_data,
- const RuntimeShape& input2_shape,
- const float* input2_data,
- const RuntimeShape& output_shape,
- float* output_data) {
- NdArrayDesc<4> desc1;
- NdArrayDesc<4> desc2;
- NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1,
- &desc2);
- const RuntimeShape extended_output_shape =
- RuntimeShape::ExtendedShape(4, output_shape);
-
- // In Tensorflow, the dimensions are canonically named (batch_number, row,
- // col, channel), with extents (batches, height, width, depth), with the
- // trailing dimension changing most rapidly (channels has the smallest stride,
- // typically 1 element).
- //
- // In generated C code, we store arrays with the dimensions reversed. The
- // first dimension has smallest stride.
- //
- // We name our variables by their Tensorflow convention, but generate C code
- // nesting loops such that the innermost loop has the smallest stride for the
- // best cache behavior.
- for (int b = 0; b < extended_output_shape.Dims(0); ++b) {
- for (int y = 0; y < extended_output_shape.Dims(1); ++y) {
- for (int x = 0; x < extended_output_shape.Dims(2); ++x) {
- for (int c = 0; c < extended_output_shape.Dims(3); ++c) {
- output_data[Offset(extended_output_shape, b, y, x, c)] =
- ActivationFunctionWithMinMax(
- input1_data[SubscriptToIndex(desc1, b, y, x, c)] +
- input2_data[SubscriptToIndex(desc2, b, y, x, c)],
- params.float_activation_min, params.float_activation_max);
- }
- }
- }
- }
-}
-
-inline void BroadcastAdd4DSlow(const ArithmeticParams& params,
- const RuntimeShape& input1_shape,
- const int32_t* input1_data,
- const RuntimeShape& input2_shape,
- const int32_t* input2_data,
- const RuntimeShape& output_shape,
- int32_t* output_data) {
- NdArrayDesc<4> desc1;
- NdArrayDesc<4> desc2;
- NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1,
- &desc2);
- const RuntimeShape extended_output_shape =
- RuntimeShape::ExtendedShape(4, output_shape);
-
- // In Tensorflow, the dimensions are canonically named (batch_number, row,
- // col, channel), with extents (batches, height, width, depth), with the
- // trailing dimension changing most rapidly (channels has the smallest stride,
- // typically 1 element).
- //
- // In generated C code, we store arrays with the dimensions reversed. The
- // first dimension has smallest stride.
- //
- // We name our variables by their Tensorflow convention, but generate C code
- // nesting loops such that the innermost loop has the smallest stride for the
- // best cache behavior.
- for (int b = 0; b < extended_output_shape.Dims(0); ++b) {
- for (int y = 0; y < extended_output_shape.Dims(1); ++y) {
- for (int x = 0; x < extended_output_shape.Dims(2); ++x) {
- for (int c = 0; c < extended_output_shape.Dims(3); ++c) {
- output_data[Offset(extended_output_shape, b, y, x, c)] =
- ActivationFunctionWithMinMax(
- input1_data[SubscriptToIndex(desc1, b, y, x, c)] +
- input2_data[SubscriptToIndex(desc2, b, y, x, c)],
- params.quantized_activation_min,
- params.quantized_activation_max);
- }
- }
- }
- }
-}
-
-// This function is used for 8-bit as well as for 16-bit, but the accumulator
-// is 32-bit for both cases. The overflow does not happen due to the
-// choice of the shift (20 or 15, accordingly - see add.cc for more comments).
-template
-inline void BroadcastAdd4DSlow(
- const ArithmeticParams& params, const RuntimeShape& input1_shape,
- const T* input1_data, const RuntimeShape& input2_shape,
- const T* input2_data, const RuntimeShape& output_shape, T* output_data) {
- NdArrayDesc<4> desc1;
- NdArrayDesc<4> desc2;
- NdArrayDescsForElementwiseBroadcast(input1_shape, input2_shape, &desc1,
- &desc2);
- const RuntimeShape extended_output_shape =
- RuntimeShape::ExtendedShape(4, output_shape);
-
- // In Tensorflow, the dimensions are canonically named (batch_number, row,
- // col, channel), with extents (batches, height, width, depth), with the
- // trailing dimension changing most rapidly (channels has the smallest stride,
- // typically 1 element).
- //
- // In generated C code, we store arrays with the dimensions reversed. The
- // first dimension has smallest stride.
- //
- // We name our variables by their Tensorflow convention, but generate C code
- // nesting loops such that the innermost loop has the smallest stride for the
- // best cache behavior.
- for (int b = 0; b < extended_output_shape.Dims(0); ++b) {
- for (int y = 0; y < extended_output_shape.Dims(1); ++y) {
- for (int x = 0; x < extended_output_shape.Dims(2); ++x) {
- for (int c = 0; c < extended_output_shape.Dims(3); ++c) {
- const int32_t input1_val =
- params.input1_offset +
- input1_data[SubscriptToIndex(desc1, b, y, x, c)];
- const int32_t input2_val =
- params.input2_offset +
- input2_data[SubscriptToIndex(desc2, b, y, x, c)];
- const int32_t shifted_input1_val =
- input1_val * (1 << params.left_shift);
- const int32_t shifted_input2_val =
- input2_val * (1 << params.left_shift);
- const int32_t scaled_input1_val =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- shifted_input1_val, params.input1_multiplier,
- params.input1_shift);
- const int32_t scaled_input2_val =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- shifted_input2_val, params.input2_multiplier,
- params.input2_shift);
- const int32_t raw_sum = scaled_input1_val + scaled_input2_val;
- const int32_t raw_output =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- raw_sum, params.output_multiplier, params.output_shift) +
- params.output_offset;
- const int32_t clamped_output =
- std::min(params.quantized_activation_max,
- std::max(params.quantized_activation_min, raw_output));
- output_data[Offset(extended_output_shape, b, y, x, c)] =
- static_cast(clamped_output);
- }
- }
- }
- }
-}
-
-inline void BroadcastAddFivefold(const ArithmeticParams& unswitched_params,
- const RuntimeShape& unswitched_input1_shape,
- const uint8_t* unswitched_input1_data,
- const RuntimeShape& unswitched_input2_shape,
- const uint8_t* unswitched_input2_data,
- const RuntimeShape& output_shape,
- uint8_t* output_data) {
- ArithmeticParams switched_params = unswitched_params;
- switched_params.input1_offset = unswitched_params.input2_offset;
- switched_params.input1_multiplier = unswitched_params.input2_multiplier;
- switched_params.input1_shift = unswitched_params.input2_shift;
- switched_params.input2_offset = unswitched_params.input1_offset;
- switched_params.input2_multiplier = unswitched_params.input1_multiplier;
- switched_params.input2_shift = unswitched_params.input1_shift;
-
- const bool use_unswitched =
- unswitched_params.broadcast_category ==
- tflite::BroadcastableOpCategory::kFirstInputBroadcastsFast;
-
- const ArithmeticParams& params =
- use_unswitched ? unswitched_params : switched_params;
- const uint8_t* input1_data =
- use_unswitched ? unswitched_input1_data : unswitched_input2_data;
- const uint8_t* input2_data =
- use_unswitched ? unswitched_input2_data : unswitched_input1_data;
-
- // Fivefold nested loops. The second input resets its position for each
- // iteration of the second loop. The first input resets its position at the
- // beginning of the fourth loop. The innermost loop is an elementwise add of
- // sections of the arrays.
- uint8_t* output_data_ptr = output_data;
- const uint8_t* input1_data_ptr = input1_data;
- const uint8_t* input2_data_reset = input2_data;
- // In the fivefold pattern, y0, y2 and y4 are not broadcast, and so shared
- // between input shapes. y3 for input 1 is always broadcast, and so the
- // dimension there is 1, whereas optionally y1 might be broadcast for input 2.
- // Put another way,
- // input1.shape.FlatSize = y0 * y1 * y2 * y4,
- // input2.shape.FlatSize = y0 * y2 * y3 * y4.
- int y0 = params.broadcast_shape[0];
- int y1 = params.broadcast_shape[1];
- int y2 = params.broadcast_shape[2];
- int y3 = params.broadcast_shape[3];
- int y4 = params.broadcast_shape[4];
- if (y4 > 1) {
- // General fivefold pattern, with y4 > 1 so there is a non-broadcast inner
- // dimension.
- for (int i0 = 0; i0 < y0; ++i0) {
- const uint8_t* input2_data_ptr;
- for (int i1 = 0; i1 < y1; ++i1) {
- input2_data_ptr = input2_data_reset;
- for (int i2 = 0; i2 < y2; ++i2) {
- for (int i3 = 0; i3 < y3; ++i3) {
- AddElementwise(y4, params, input1_data_ptr, input2_data_ptr,
- output_data_ptr);
- input2_data_ptr += y4;
- output_data_ptr += y4;
- }
- // We have broadcast y4 of input1 data y3 times, and now move on.
- input1_data_ptr += y4;
- }
- }
- // We have broadcast y2*y3*y4 of input2 data y1 times, and now move on.
- input2_data_reset = input2_data_ptr;
- }
- } else {
- // Special case of y4 == 1, in which the innermost loop is a single element
- // and can be combined with the next (y3) as an inner broadcast.
- //
- // Note that this handles the case of pure scalar broadcast when
- // y0 == y1 == y2 == 1. With low overhead it handles cases such as scalar
- // broadcast with batch (as y2 > 1).
- //
- // NOTE The process is the same as the above general case except simplified
- // for y4 == 1 and the loop over y3 is contained within the
- // AddScalarBroadcast function.
- for (int i0 = 0; i0 < y0; ++i0) {
- const uint8_t* input2_data_ptr;
- for (int i1 = 0; i1 < y1; ++i1) {
- input2_data_ptr = input2_data_reset;
- for (int i2 = 0; i2 < y2; ++i2) {
- AddScalarBroadcast(y3, params, *input1_data_ptr, input2_data_ptr,
- output_data_ptr);
- input2_data_ptr += y3;
- output_data_ptr += y3;
- input1_data_ptr += 1;
- }
- }
- input2_data_reset = input2_data_ptr;
- }
- }
-}
-
-} // namespace reference_ops
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ADD_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/arg_min_max.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/arg_min_max.h
deleted file mode 100644
index e6f34fd73f432a8c4986c7bbbf36d76dd153525b..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/arg_min_max.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/* 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ARG_MIN_MAX_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ARG_MIN_MAX_H_
-
-#include "tensorflow/lite/kernels/internal/types.h"
-
-namespace tflite {
-
-namespace reference_ops {
-
-template
-void ArgMinMax(const RuntimeShape& input1_shape, const T1* input1_data,
- const T3* input2_data, const RuntimeShape& output_shape,
- T2* output_data, const Cmp& cmp) {
- TFLITE_DCHECK_GT(input1_shape.DimensionsCount(), 0);
- TFLITE_DCHECK_EQ(input1_shape.DimensionsCount() - 1,
- output_shape.DimensionsCount());
- int axis = input2_data[0];
- if (axis < 0) {
- axis += input1_shape.DimensionsCount();
- }
- const int axis_size = input1_shape.Dims(axis);
-
- int outer_size = 1;
- for (int i = 0; i < axis; ++i) {
- TFLITE_DCHECK_EQ(input1_shape.Dims(i), output_shape.Dims(i));
- outer_size *= input1_shape.Dims(i);
- }
-
- int inner_size = 1;
- const int dims_count = input1_shape.DimensionsCount();
- for (int i = axis + 1; i < dims_count; ++i) {
- TFLITE_DCHECK_EQ(input1_shape.Dims(i), output_shape.Dims(i - 1));
- inner_size *= input1_shape.Dims(i);
- }
- for (int outer = 0; outer < outer_size; ++outer) {
- for (int inner = 0; inner < inner_size; ++inner) {
- auto min_max_value = input1_data[outer * axis_size * inner_size + inner];
- T2 min_max_index = 0;
- for (int i = 1; i < axis_size; ++i) {
- const auto& curr_value =
- input1_data[(outer * axis_size + i) * inner_size + inner];
- if (cmp(curr_value, min_max_value)) {
- min_max_value = curr_value;
- min_max_index = static_cast(i);
- }
- }
- output_data[outer * inner_size + inner] = min_max_index;
- }
- }
-}
-} // namespace reference_ops
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ARG_MIN_MAX_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/binary_function.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/binary_function.h
deleted file mode 100644
index 51d9e2b711a243e56fb9c27745d83bafe67e88de..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/binary_function.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/* 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BINARY_FUNCTION_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BINARY_FUNCTION_H_
-
-#include "tensorflow/lite/kernels/internal/common.h"
-#include "tensorflow/lite/kernels/internal/compatibility.h"
-#include "tensorflow/lite/kernels/internal/types.h"
-
-namespace tflite {
-
-namespace reference_ops {
-
-// TODO(ycling): Refactoring. Remove BroadcastLogical and use the more
-// generalized and efficient BroadcastBinaryFunction.
-//
-// Also appears to duplicate MinimumMaximum.
-//
-// R: Result type. T1: Input 1 type. T2: Input 2 type.
-template
-inline void BroadcastBinaryFunction4DSlow(
- const RuntimeShape& unextended_input1_shape, const T1* input1_data,
- const RuntimeShape& unextended_input2_shape, const T2* input2_data,
- const RuntimeShape& unextended_output_shape, R* output_data,
- R (*func)(T1, T2)) {
- TFLITE_DCHECK_LE(unextended_input1_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_LE(unextended_input2_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4);
- const RuntimeShape output_shape =
- RuntimeShape::ExtendedShape(4, unextended_output_shape);
-
- NdArrayDesc<4> desc1;
- NdArrayDesc<4> desc2;
- NdArrayDescsForElementwiseBroadcast(unextended_input1_shape,
- unextended_input2_shape, &desc1, &desc2);
-
- for (int b = 0; b < output_shape.Dims(0); ++b) {
- for (int y = 0; y < output_shape.Dims(1); ++y) {
- for (int x = 0; x < output_shape.Dims(2); ++x) {
- for (int c = 0; c < output_shape.Dims(3); ++c) {
- auto out_idx = Offset(output_shape, b, y, x, c);
- auto in1_idx = SubscriptToIndex(desc1, b, y, x, c);
- auto in2_idx = SubscriptToIndex(desc2, b, y, x, c);
- auto in1_val = input1_data[in1_idx];
- auto in2_val = input2_data[in2_idx];
- output_data[out_idx] = func(in1_val, in2_val);
- }
- }
- }
- }
-}
-
-// R: Result type. T1: Input 1 type. T2: Input 2 type.
-// TODO(renjieliu): Refactor other binary functions to use this one.
-template
-inline void BinaryFunction(const RuntimeShape& input1_shape,
- const T1* input1_data,
- const RuntimeShape& input2_shape,
- const T2* input2_data,
- const RuntimeShape& output_shape, R* output_data,
- R (*func)(T1, T2)) {
- const int flat_size =
- MatchingFlatSize(input1_shape, input2_shape, output_shape);
- for (int i = 0; i < flat_size; ++i) {
- output_data[i] = func(input1_data[i], input2_data[i]);
- }
-}
-
-} // namespace reference_ops
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_BINARY_FUNCTION_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/ceil.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/ceil.h
deleted file mode 100644
index 66d1dc3599c081fca88095a5e2cc76918c0bdb1e..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/ceil.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Copyright 2018 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CEIL_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CEIL_H_
-
-#include
-
-#include "tensorflow/lite/kernels/internal/types.h"
-
-namespace tflite {
-
-namespace reference_ops {
-
-inline void Ceil(const RuntimeShape& input_shape, const float* input_data,
- const RuntimeShape& output_shape, float* output_data) {
- const int flat_size = MatchingFlatSize(input_shape, output_shape);
-
- for (int i = 0; i < flat_size; ++i) {
- output_data[i] = std::ceil(input_data[i]);
- }
-}
-
-} // namespace reference_ops
-} // namespace tflite
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CEIL_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/comparisons.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/comparisons.h
deleted file mode 100644
index 49844ab1539c33fb877b24e1aac33ce54a3c0c9b..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/comparisons.h
+++ /dev/null
@@ -1,334 +0,0 @@
-/* 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_COMPARISONS_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_COMPARISONS_H_
-
-#include "tensorflow/lite/c/common.h"
-#include "tensorflow/lite/kernels/internal/common.h"
-#include "tensorflow/lite/kernels/internal/types.h"
-#include "tensorflow/lite/string_util.h"
-
-namespace tflite {
-
-namespace reference_ops {
-
-template
-inline bool EqualFn(T lhs, T rhs) {
- return lhs == rhs;
-}
-
-template
-inline bool NotEqualFn(T lhs, T rhs) {
- return lhs != rhs;
-}
-
-template
-inline bool GreaterFn(T lhs, T rhs) {
- return lhs > rhs;
-}
-template
-inline bool GreaterEqualFn(T lhs, T rhs) {
- return lhs >= rhs;
-}
-template
-inline bool LessFn(T lhs, T rhs) {
- return lhs < rhs;
-}
-template
-inline bool LessEqualFn(T lhs, T rhs) {
- return lhs <= rhs;
-}
-
-inline bool StringRefEqualFn(const StringRef& lhs, const StringRef& rhs) {
- if (lhs.len != rhs.len) return false;
- for (int i = 0; i < lhs.len; ++i) {
- if (lhs.str[i] != rhs.str[i]) return false;
- }
- return true;
-}
-
-inline bool StringRefNotEqualFn(const StringRef& lhs, const StringRef& rhs) {
- return !StringRefEqualFn(lhs, rhs);
-}
-
-template
-using ComparisonFn = bool (*)(T, T);
-
-template F>
-inline void ComparisonImpl(
- const ComparisonParams& op_params, const RuntimeShape& input1_shape,
- const T* input1_data, const RuntimeShape& input2_shape,
- const T* input2_data, const RuntimeShape& output_shape, bool* output_data) {
- const int64_t flatsize =
- MatchingFlatSize(input1_shape, input2_shape, output_shape);
- for (int64_t i = 0; i < flatsize; ++i) {
- output_data[i] = F(input1_data[i], input2_data[i]);
- }
-}
-
-inline void ComparisonStringImpl(bool (*F)(const StringRef&, const StringRef&),
- const RuntimeShape& input1_shape,
- const TfLiteTensor* input1,
- const RuntimeShape& input2_shape,
- const TfLiteTensor* input2,
- const RuntimeShape& output_shape,
- bool* output_data) {
- const int64_t flatsize =
- MatchingFlatSize(input1_shape, input2_shape, output_shape);
- for (int64_t i = 0; i < flatsize; ++i) {
- const auto lhs = GetString(input1, i);
- const auto rhs = GetString(input2, i);
- output_data[i] = F(lhs, rhs);
- }
-}
-
-template F>
-inline void Comparison(const ComparisonParams& op_params,
- const RuntimeShape& input1_shape,
- const float* input1_data,
- const RuntimeShape& input2_shape,
- const float* input2_data,
- const RuntimeShape& output_shape, bool* output_data) {
- ComparisonImpl(op_params, input1_shape, input1_data, input2_shape,
- input2_data, output_shape, output_data);
-}
-
-template F>
-inline void ComparisonWithScaling(
- const ComparisonParams& op_params, const RuntimeShape& input1_shape,
- const T* input1_data, const RuntimeShape& input2_shape,
- const T* input2_data, const RuntimeShape& output_shape, bool* output_data) {
- int left_shift = op_params.left_shift;
- int32_t input1_offset = op_params.input1_offset;
- int32_t input1_multiplier = op_params.input1_multiplier;
- int input1_shift = op_params.input1_shift;
- int32_t input2_offset = op_params.input2_offset;
- int32_t input2_multiplier = op_params.input2_multiplier;
- int input2_shift = op_params.input2_shift;
-
- const int64_t flatsize =
- MatchingFlatSize(input1_shape, input2_shape, output_shape);
- for (int64_t i = 0; i < flatsize; ++i) {
- const int32_t input1_val = input1_offset + input1_data[i];
- const int32_t input2_val = input2_offset + input2_data[i];
- const int32_t shifted_input1_val = input1_val * (1 << left_shift);
- const int32_t shifted_input2_val = input2_val * (1 << left_shift);
- const int32_t scaled_input1_val =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- shifted_input1_val, input1_multiplier, input1_shift);
- const int32_t scaled_input2_val =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- shifted_input2_val, input2_multiplier, input2_shift);
- output_data[i] = F(scaled_input1_val, scaled_input2_val);
- }
-}
-
-struct BroadcastComparison4DSlowCommon {
- const RuntimeShape output_shape;
- NdArrayDesc<4> desc1;
- NdArrayDesc<4> desc2;
-};
-
-inline BroadcastComparison4DSlowCommon BroadcastComparison4DSlowPreprocess(
- const RuntimeShape& unextended_input1_shape,
- const RuntimeShape& unextended_input2_shape,
- const RuntimeShape& unextended_output_shape) {
- TFLITE_DCHECK_LE(unextended_input1_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_LE(unextended_input2_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_LE(unextended_output_shape.DimensionsCount(), 4);
- NdArrayDesc<4> desc1;
- NdArrayDesc<4> desc2;
- NdArrayDescsForElementwiseBroadcast(unextended_input1_shape,
- unextended_input2_shape, &desc1, &desc2);
- return {RuntimeShape::ExtendedShape(4, unextended_output_shape), desc1,
- desc2};
-}
-
-template F>
-inline void BroadcastComparison4DSlowImpl(
- const ComparisonParams& op_params,
- const RuntimeShape& unextended_input1_shape, const T* input1_data,
- const RuntimeShape& unextended_input2_shape, const T* input2_data,
- const RuntimeShape& unextended_output_shape, bool* output_data) {
- const BroadcastComparison4DSlowCommon dims =
- BroadcastComparison4DSlowPreprocess(unextended_input1_shape,
- unextended_input2_shape,
- unextended_output_shape);
-
- for (int b = 0; b < dims.output_shape.Dims(0); ++b) {
- for (int y = 0; y < dims.output_shape.Dims(1); ++y) {
- for (int x = 0; x < dims.output_shape.Dims(2); ++x) {
- for (int c = 0; c < dims.output_shape.Dims(3); ++c) {
- output_data[Offset(dims.output_shape, b, y, x, c)] =
- F(input1_data[SubscriptToIndex(dims.desc1, b, y, x, c)],
- input2_data[SubscriptToIndex(dims.desc2, b, y, x, c)]);
- }
- }
- }
- }
-}
-
-inline void BroadcastComparison4DSlowStringImpl(
- bool (*F)(const StringRef&, const StringRef&),
- const RuntimeShape& unextended_input1_shape, const TfLiteTensor* input1,
- const RuntimeShape& unextended_input2_shape, const TfLiteTensor* input2,
- const RuntimeShape& unextended_output_shape, bool* output_data) {
- const BroadcastComparison4DSlowCommon dims =
- BroadcastComparison4DSlowPreprocess(unextended_input1_shape,
- unextended_input2_shape,
- unextended_output_shape);
-
- for (int b = 0; b < dims.output_shape.Dims(0); ++b) {
- for (int y = 0; y < dims.output_shape.Dims(1); ++y) {
- for (int x = 0; x < dims.output_shape.Dims(2); ++x) {
- for (int c = 0; c < dims.output_shape.Dims(3); ++c) {
- const auto lhs =
- GetString(input1, SubscriptToIndex(dims.desc1, b, y, x, c));
- const auto rhs =
- GetString(input2, SubscriptToIndex(dims.desc2, b, y, x, c));
- output_data[Offset(dims.output_shape, b, y, x, c)] = F(lhs, rhs);
- }
- }
- }
- }
-}
-
-template F>
-inline void BroadcastComparison4DSlow(const ComparisonParams& op_params,
- const RuntimeShape& input1_shape,
- const float* input1_data,
- const RuntimeShape& input2_shape,
- const float* input2_data,
- const RuntimeShape& output_shape,
- bool* output_data) {
- BroadcastComparison4DSlowImpl(op_params, input1_shape, input1_data,
- input2_shape, input2_data,
- output_shape, output_data);
-}
-
-template F>
-inline void BroadcastComparison4DSlowWithScaling(
- const ComparisonParams& op_params,
- const RuntimeShape& unextended_input1_shape, const T* input1_data,
- const RuntimeShape& unextended_input2_shape, const T* input2_data,
- const RuntimeShape& unextended_output_shape, bool* output_data) {
- const BroadcastComparison4DSlowCommon dims =
- BroadcastComparison4DSlowPreprocess(unextended_input1_shape,
- unextended_input2_shape,
- unextended_output_shape);
-
- int left_shift = op_params.left_shift;
- int32_t input1_offset = op_params.input1_offset;
- int32_t input1_multiplier = op_params.input1_multiplier;
- int input1_shift = op_params.input1_shift;
- int32_t input2_offset = op_params.input2_offset;
- int32_t input2_multiplier = op_params.input2_multiplier;
- int input2_shift = op_params.input2_shift;
-
- for (int b = 0; b < dims.output_shape.Dims(0); ++b) {
- for (int y = 0; y < dims.output_shape.Dims(1); ++y) {
- for (int x = 0; x < dims.output_shape.Dims(2); ++x) {
- for (int c = 0; c < dims.output_shape.Dims(3); ++c) {
- const int32_t input1_val =
- input1_offset +
- input1_data[SubscriptToIndex(dims.desc1, b, y, x, c)];
- const int32_t input2_val =
- input2_offset +
- input2_data[SubscriptToIndex(dims.desc2, b, y, x, c)];
- const int32_t shifted_input1_val = input1_val * (1 << left_shift);
- const int32_t shifted_input2_val = input2_val * (1 << left_shift);
- const int32_t scaled_input1_val =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- shifted_input1_val, input1_multiplier, input1_shift);
- const int32_t scaled_input2_val =
- MultiplyByQuantizedMultiplierSmallerThanOneExp(
- shifted_input2_val, input2_multiplier, input2_shift);
- output_data[Offset(dims.output_shape, b, y, x, c)] =
- F(scaled_input1_val, scaled_input2_val);
- }
- }
- }
- }
-}
-
-#define TFLITE_COMPARISON_OP(name) \
- inline void name(const ComparisonParams& op_params, \
- const RuntimeShape& input1_shape, const float* input1_data, \
- const RuntimeShape& input2_shape, const float* input2_data, \
- const RuntimeShape& output_shape, bool* output_data) { \
- Comparison(op_params, input1_shape, input1_data, input2_shape, \
- input2_data, output_shape, output_data); \
- } \
- template \
- inline void name##NoScaling( \
- const ComparisonParams& op_params, const RuntimeShape& input1_shape, \
- const T* input1_data, const RuntimeShape& input2_shape, \
- const T* input2_data, const RuntimeShape& output_shape, \
- bool* output_data) { \
- ComparisonImpl(op_params, input1_shape, input1_data, \
- input2_shape, input2_data, output_shape, \
- output_data); \
- } \
- template \
- inline void name##WithScaling( \
- const ComparisonParams& op_params, const RuntimeShape& input1_shape, \
- const T* input1_data, const RuntimeShape& input2_shape, \
- const T* input2_data, const RuntimeShape& output_shape, \
- bool* output_data) { \
- ComparisonWithScaling(op_params, input1_shape, input1_data, \
- input2_shape, input2_data, \
- output_shape, output_data); \
- } \
- template \
- inline void Broadcast4DSlow##name##NoScaling( \
- const ComparisonParams& op_params, const RuntimeShape& input1_shape, \
- const T* input1_data, const RuntimeShape& input2_shape, \
- const T* input2_data, const RuntimeShape& output_shape, \
- bool* output_data) { \
- BroadcastComparison4DSlowImpl( \
- op_params, input1_shape, input1_data, input2_shape, input2_data, \
- output_shape, output_data); \
- } \
- inline void Broadcast4DSlow##name( \
- const ComparisonParams& op_params, const RuntimeShape& input1_shape, \
- const float* input1_data, const RuntimeShape& input2_shape, \
- const float* input2_data, const RuntimeShape& output_shape, \
- bool* output_data) { \
- BroadcastComparison4DSlow(op_params, input1_shape, input1_data, \
- input2_shape, input2_data, \
- output_shape, output_data); \
- } \
- template \
- inline void Broadcast4DSlow##name##WithScaling( \
- const ComparisonParams& op_params, const RuntimeShape& input1_shape, \
- const T* input1_data, const RuntimeShape& input2_shape, \
- const T* input2_data, const RuntimeShape& output_shape, \
- bool* output_data) { \
- BroadcastComparison4DSlowWithScaling( \
- op_params, input1_shape, input1_data, input2_shape, input2_data, \
- output_shape, output_data); \
- }
-TFLITE_COMPARISON_OP(Equal);
-TFLITE_COMPARISON_OP(NotEqual);
-TFLITE_COMPARISON_OP(Greater);
-TFLITE_COMPARISON_OP(GreaterEqual);
-TFLITE_COMPARISON_OP(Less);
-TFLITE_COMPARISON_OP(LessEqual);
-#undef TFLITE_COMPARISON_OP
-
-} // namespace reference_ops
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_COMPARISONS_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/concatenation.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/concatenation.h
deleted file mode 100644
index 25959793e9dc054ef6e0e8c46096c2a180454110..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/concatenation.h
+++ /dev/null
@@ -1,140 +0,0 @@
-/* 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.
-==============================================================================*/
-
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONCATENATION_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONCATENATION_H_
-
-#include "tensorflow/lite/kernels/internal/common.h"
-#include "tensorflow/lite/kernels/internal/compatibility.h"
-#include "tensorflow/lite/kernels/internal/cppmath.h"
-#include "tensorflow/lite/kernels/internal/types.h"
-
-namespace tflite {
-namespace reference_ops {
-
-template
-inline void Concatenation(const ConcatenationParams& params,
- const RuntimeShape* const* input_shapes,
- const Scalar* const* input_data,
- const RuntimeShape& output_shape,
- Scalar* output_data) {
- int axis = params.axis;
- int inputs_count = params.inputs_count;
- const int concat_dimensions = output_shape.DimensionsCount();
- TFLITE_DCHECK_LT(axis, concat_dimensions);
-
- int64_t concat_size = 0;
- for (int i = 0; i < inputs_count; i++) {
- TFLITE_DCHECK_EQ(input_shapes[i]->DimensionsCount(), concat_dimensions);
- for (int j = 0; j < concat_dimensions; j++) {
- if (j != axis) {
- MatchingDim(*input_shapes[i], j, output_shape, j);
- }
- }
- concat_size += input_shapes[i]->Dims(axis);
- }
- TFLITE_DCHECK_EQ(concat_size, output_shape.Dims(axis));
- int64_t outer_size = 1;
- for (int i = 0; i < axis; ++i) {
- outer_size *= output_shape.Dims(i);
- }
- // For all input arrays,
- // FlatSize() = outer_size * Dims(axis) * base_inner_size;
- int64_t base_inner_size = 1;
- for (int i = axis + 1; i < concat_dimensions; ++i) {
- base_inner_size *= output_shape.Dims(i);
- }
-
- Scalar* output_ptr = output_data;
- for (int k = 0; k < outer_size; k++) {
- for (int i = 0; i < inputs_count; ++i) {
- const int copy_size = input_shapes[i]->Dims(axis) * base_inner_size;
- const Scalar* input_ptr = input_data[i] + k * copy_size;
- memcpy(output_ptr, input_ptr, copy_size * sizeof(Scalar));
- output_ptr += copy_size;
- }
- }
-}
-
-// TODO(prabhumk): This is the same as the optimized implementation.
-// TODO(prabhumk): The quantized implementation of concatentation isn't fully
-// quantized as it takes scale as a floating point value. This should be fixed
-// when optimizng this routine further.
-inline void ConcatenationWithScaling(const ConcatenationParams& params,
- const RuntimeShape* const* input_shapes,
- const uint8_t* const* input_data,
- const RuntimeShape& output_shape,
- uint8_t* output_data) {
- int axis = params.axis;
- const int32_t* input_zeropoint = params.input_zeropoint;
- const float* input_scale = params.input_scale;
- int inputs_count = params.inputs_count;
- const int32_t output_zeropoint = params.output_zeropoint;
- const float output_scale = params.output_scale;
-
- const int concat_dimensions = output_shape.DimensionsCount();
- TFLITE_DCHECK_LT(axis, concat_dimensions);
-
- int64_t concat_size = 0;
- for (int i = 0; i < inputs_count; i++) {
- TFLITE_DCHECK_EQ(input_shapes[i]->DimensionsCount(), concat_dimensions);
- for (int j = 0; j < concat_dimensions; j++) {
- if (j != axis) {
- MatchingDim(*input_shapes[i], j, output_shape, j);
- }
- }
- concat_size += input_shapes[i]->Dims(axis);
- }
- TFLITE_DCHECK_EQ(concat_size, output_shape.Dims(axis));
- int64_t outer_size = 1;
- for (int i = 0; i < axis; ++i) {
- outer_size *= output_shape.Dims(i);
- }
- // For all input arrays,
- // FlatSize() = outer_size * Dims(axis) * base_inner_size;
- int64_t base_inner_size = 1;
- for (int i = axis + 1; i < concat_dimensions; ++i) {
- base_inner_size *= output_shape.Dims(i);
- }
-
- const float inverse_output_scale = 1.f / output_scale;
- uint8_t* output_ptr = output_data;
- for (int k = 0; k < outer_size; k++) {
- for (int i = 0; i < inputs_count; ++i) {
- const int copy_size = input_shapes[i]->Dims(axis) * base_inner_size;
- const uint8_t* input_ptr = input_data[i] + k * copy_size;
- if (input_zeropoint[i] == output_zeropoint &&
- input_scale[i] == output_scale) {
- memcpy(output_ptr, input_ptr, copy_size);
- } else {
- const float scale = input_scale[i] * inverse_output_scale;
- const float bias = -input_zeropoint[i] * scale;
- for (int j = 0; j < copy_size; ++j) {
- const int32_t value = static_cast(tflite::TfLiteRound(
- input_ptr[j] * scale + bias)) +
- output_zeropoint;
- output_ptr[j] = static_cast(
- std::max(std::min(255, value), 0));
- }
- }
- output_ptr += copy_size;
- }
- }
-}
-
-} // namespace reference_ops
-} // namespace tflite
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONCATENATION_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/conv.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/conv.h
deleted file mode 100644
index d4bf46a86b892bd98bf0dc680aaba2580b42128d..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/conv.h
+++ /dev/null
@@ -1,262 +0,0 @@
-/* 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONV_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONV_H_
-
-#include "tensorflow/lite/kernels/internal/types.h"
-#include "tensorflow/lite/kernels/internal/common.h"
-
-
-
-namespace tflite {
-
-namespace reference_ops {
-
-
-inline void Conv(const ConvParams& params, const RuntimeShape& input_shape,
- const float* input_data, const RuntimeShape& filter_shape,
- const float* filter_data, const RuntimeShape& bias_shape,
- const float* bias_data, const RuntimeShape& output_shape,
- float* output_data, const RuntimeShape& im2col_shape,
- float* im2col_data) {
- const int stride_width = params.stride_width;
- const int stride_height = params.stride_height;
- const int dilation_width_factor = params.dilation_width_factor;
- const int dilation_height_factor = params.dilation_height_factor;
- const int pad_width = params.padding_values.width;
- const int pad_height = params.padding_values.height;
- const float output_activation_min = params.float_activation_min;
- const float output_activation_max = params.float_activation_max;
- TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4);
-
- (void)im2col_data; // only used in optimized code.
- (void)im2col_shape; // only used in optimized code.
- const int batches = MatchingDim(input_shape, 0, output_shape, 0);
- const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3);
- const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3);
- if (bias_data) {
- TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth);
- }
- const int input_height = input_shape.Dims(1);
- const int input_width = input_shape.Dims(2);
- const int filter_height = filter_shape.Dims(1);
- const int filter_width = filter_shape.Dims(2);
- const int output_height = output_shape.Dims(1);
- const int output_width = output_shape.Dims(2);
- for (int batch = 0; batch < batches; ++batch) {
- for (int out_y = 0; out_y < output_height; ++out_y) {
- for (int out_x = 0; out_x < output_width; ++out_x) {
- for (int out_channel = 0; out_channel < output_depth; ++out_channel) {
- const int in_x_origin = (out_x * stride_width) - pad_width;
- const int in_y_origin = (out_y * stride_height) - pad_height;
- float total = 0.f;
- for (int filter_y = 0; filter_y < filter_height; ++filter_y) {
- for (int filter_x = 0; filter_x < filter_width; ++filter_x) {
- for (int in_channel = 0; in_channel < input_depth; ++in_channel) {
- const int in_x = in_x_origin + dilation_width_factor * filter_x;
- const int in_y =
- in_y_origin + dilation_height_factor * filter_y;
- // If the location is outside the bounds of the input image,
- // use zero as a default value.
- if ((in_x >= 0) && (in_x < input_width) && (in_y >= 0) &&
- (in_y < input_height)) {
- float input_value = input_data[Offset(
- input_shape, batch, in_y, in_x, in_channel)];
- float filter_value =
- filter_data[Offset(filter_shape, out_channel, filter_y,
- filter_x, in_channel)];
- total += (input_value * filter_value);
- }
- }
- }
- }
- float bias_value = 0.0f;
- if (bias_data) {
- bias_value = bias_data[out_channel];
- }
- output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] =
- ActivationFunctionWithMinMax(total + bias_value,
- output_activation_min,
- output_activation_max);
- }
- }
- }
- }
-}
-
-inline void Conv(const ConvParams& params, const RuntimeShape& input_shape,
- const uint8_t* input_data, const RuntimeShape& filter_shape,
- const uint8_t* filter_data, const RuntimeShape& bias_shape,
- const int32_t* bias_data, const RuntimeShape& output_shape,
- uint8_t* output_data, const RuntimeShape& im2col_shape,
- uint8_t* im2col_data, void* cpu_backend_context) {
- (void)cpu_backend_context; // only used in optimized code.
- (void)im2col_data; // only used in optimized code.
- (void)im2col_shape; // only used in optimized code.
- const int stride_width = params.stride_width;
- const int stride_height = params.stride_height;
- const int dilation_width_factor = params.dilation_width_factor;
- const int dilation_height_factor = params.dilation_height_factor;
- const int pad_width = params.padding_values.width;
- const int pad_height = params.padding_values.height;
- const int32_t input_offset = params.input_offset;
- const int32_t filter_offset = params.weights_offset;
- const int32_t output_offset = params.output_offset;
- const int32_t output_multiplier = params.output_multiplier;
- const int output_shift = params.output_shift;
- const int32_t output_activation_min = params.quantized_activation_min;
- const int32_t output_activation_max = params.quantized_activation_max;
- TFLITE_DCHECK_LE(output_activation_min, output_activation_max);
-
- TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4);
- const int batches = MatchingDim(input_shape, 0, output_shape, 0);
- const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3);
- const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3);
- if (bias_data) {
- TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth);
- }
- const int input_height = input_shape.Dims(1);
- const int input_width = input_shape.Dims(2);
- const int filter_height = filter_shape.Dims(1);
- const int filter_width = filter_shape.Dims(2);
- const int output_height = output_shape.Dims(1);
- const int output_width = output_shape.Dims(2);
- for (int batch = 0; batch < batches; ++batch) {
- for (int out_y = 0; out_y < output_height; ++out_y) {
- for (int out_x = 0; out_x < output_width; ++out_x) {
- for (int out_channel = 0; out_channel < output_depth; ++out_channel) {
- const int in_x_origin = (out_x * stride_width) - pad_width;
- const int in_y_origin = (out_y * stride_height) - pad_height;
- int32_t acc = 0;
- for (int filter_y = 0; filter_y < filter_height; ++filter_y) {
- for (int filter_x = 0; filter_x < filter_width; ++filter_x) {
- for (int in_channel = 0; in_channel < input_depth; ++in_channel) {
- const int in_x = in_x_origin + dilation_width_factor * filter_x;
- const int in_y =
- in_y_origin + dilation_height_factor * filter_y;
- // If the location is outside the bounds of the input image,
- // use zero as a default value.
- if ((in_x >= 0) && (in_x < input_width) && (in_y >= 0) &&
- (in_y < input_height)) {
- int32_t input_val = input_data[Offset(
- input_shape, batch, in_y, in_x, in_channel)];
- int32_t filter_val =
- filter_data[Offset(filter_shape, out_channel, filter_y,
- filter_x, in_channel)];
- acc +=
- (filter_val + filter_offset) * (input_val + input_offset);
- }
- }
- }
- }
- if (bias_data) {
- acc += bias_data[out_channel];
- }
- acc = MultiplyByQuantizedMultiplier(acc, output_multiplier,
- output_shift);
- acc += output_offset;
- acc = std::max(acc, output_activation_min);
- acc = std::min(acc, output_activation_max);
- output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] =
- static_cast(acc);
- }
- }
- }
- }
-}
-
-inline void HybridConvPerChannel(
- const ConvParams& params, float* scaling_factors_ptr,
- const RuntimeShape& input_shape, const int8_t* input_data,
- const RuntimeShape& filter_shape, const int8_t* filter_data,
- const RuntimeShape& bias_shape, const float* bias_data,
- const RuntimeShape& output_shape, float* output_data,
- const RuntimeShape& im2col_shape, int8_t* im2col_data,
- const float* per_channel_scale, int32_t* input_offset) {
- (void)im2col_data; // only used in optimized code.
- (void)im2col_shape; // only used in optimized code.
- const int stride_width = params.stride_width;
- const int stride_height = params.stride_height;
- const int dilation_width_factor = params.dilation_width_factor;
- const int dilation_height_factor = params.dilation_height_factor;
- const int pad_width = params.padding_values.width;
- const int pad_height = params.padding_values.height;
- const float output_activation_min = params.float_activation_min;
- const float output_activation_max = params.float_activation_max;
- TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4);
- const int batches = MatchingDim(input_shape, 0, output_shape, 0);
- const int input_depth = MatchingDim(input_shape, 3, filter_shape, 3);
- const int output_depth = MatchingDim(filter_shape, 0, output_shape, 3);
- if (bias_data) {
- TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth);
- }
- const int input_height = input_shape.Dims(1);
- const int input_width = input_shape.Dims(2);
- const int filter_height = filter_shape.Dims(1);
- const int filter_width = filter_shape.Dims(2);
- const int output_height = output_shape.Dims(1);
- const int output_width = output_shape.Dims(2);
- for (int batch = 0; batch < batches; ++batch) {
- for (int out_y = 0; out_y < output_height; ++out_y) {
- for (int out_x = 0; out_x < output_width; ++out_x) {
- for (int out_channel = 0; out_channel < output_depth; ++out_channel) {
- const int in_x_origin = (out_x * stride_width) - pad_width;
- const int in_y_origin = (out_y * stride_height) - pad_height;
- int32_t acc = 0;
- for (int filter_y = 0; filter_y < filter_height; ++filter_y) {
- for (int filter_x = 0; filter_x < filter_width; ++filter_x) {
- for (int in_channel = 0; in_channel < input_depth; ++in_channel) {
- const int in_x = in_x_origin + dilation_width_factor * filter_x;
- const int in_y =
- in_y_origin + dilation_height_factor * filter_y;
- // If the location is outside the bounds of the input image,
- // use zero as a default value.
- if ((in_x >= 0) && (in_x < input_width) && (in_y >= 0) &&
- (in_y < input_height)) {
- int32_t input_val = input_data[Offset(
- input_shape, batch, in_y, in_x, in_channel)];
- int32_t filter_val =
- filter_data[Offset(filter_shape, out_channel, filter_y,
- filter_x, in_channel)];
- acc += filter_val * (input_val - input_offset[batch]);
- }
- }
- }
- }
- float acc_float =
- acc * per_channel_scale[out_channel] * scaling_factors_ptr[batch];
- if (bias_data) {
- acc_float += bias_data[out_channel];
- }
- output_data[Offset(output_shape, batch, out_y, out_x, out_channel)] =
- ActivationFunctionWithMinMax(acc_float, output_activation_min,
- output_activation_max);
- }
- }
- }
- }
-}
-
-} // namespace reference_ops
-} // namespace tflite
-
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CONV_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/depthwiseconv_float.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/depthwiseconv_float.h
deleted file mode 100644
index 0cecb16b48c9199655b393acdd347ea2e54817da..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/depthwiseconv_float.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/* Copyright 2017 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTHWISECONV_FLOAT_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTHWISECONV_FLOAT_H_
-
-#include "tensorflow/lite/kernels/internal/common.h"
-#include "tensorflow/lite/kernels/internal/compatibility.h"
-#include "tensorflow/lite/kernels/internal/types.h"
-
-namespace tflite {
-namespace reference_ops {
-
-inline void DepthwiseConv(
- const DepthwiseParams& params, const RuntimeShape& input_shape,
- const float* input_data, const RuntimeShape& filter_shape,
- const float* filter_data, const RuntimeShape& bias_shape,
- const float* bias_data, const RuntimeShape& output_shape,
- float* output_data) {
- const int stride_width = params.stride_width;
- const int stride_height = params.stride_height;
- const int dilation_width_factor = params.dilation_width_factor;
- const int dilation_height_factor = params.dilation_height_factor;
- const int pad_width = params.padding_values.width;
- const int pad_height = params.padding_values.height;
- const int depth_multiplier = params.depth_multiplier;
- const float output_activation_min = params.float_activation_min;
- const float output_activation_max = params.float_activation_max;
- TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4);
-
- const int batches = MatchingDim(input_shape, 0, output_shape, 0);
- const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3);
- const int input_height = input_shape.Dims(1);
- const int input_width = input_shape.Dims(2);
- const int input_depth = input_shape.Dims(3);
- const int filter_height = filter_shape.Dims(1);
- const int filter_width = filter_shape.Dims(2);
- const int output_height = output_shape.Dims(1);
- const int output_width = output_shape.Dims(2);
- TFLITE_DCHECK_EQ(output_depth, input_depth * depth_multiplier);
- TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth);
-
- for (int b = 0; b < batches; ++b) {
- for (int out_y = 0; out_y < output_height; ++out_y) {
- for (int out_x = 0; out_x < output_width; ++out_x) {
- for (int ic = 0; ic < input_depth; ++ic) {
- for (int m = 0; m < depth_multiplier; m++) {
- const int oc = m + ic * depth_multiplier;
- const int in_x_origin = (out_x * stride_width) - pad_width;
- const int in_y_origin = (out_y * stride_height) - pad_height;
- float total = 0.f;
- for (int filter_y = 0; filter_y < filter_height; ++filter_y) {
- for (int filter_x = 0; filter_x < filter_width; ++filter_x) {
- const int in_x = in_x_origin + dilation_width_factor * filter_x;
- const int in_y =
- in_y_origin + dilation_height_factor * filter_y;
- // If the location is outside the bounds of the input image,
- // use zero as a default value.
- if ((in_x >= 0) && (in_x < input_width) && (in_y >= 0) &&
- (in_y < input_height)) {
- float input_value =
- input_data[Offset(input_shape, b, in_y, in_x, ic)];
- float filter_value = filter_data[Offset(
- filter_shape, 0, filter_y, filter_x, oc)];
- total += (input_value * filter_value);
- }
- }
- }
- float bias_value = 0.0f;
- if (bias_data) {
- bias_value = bias_data[oc];
- }
- output_data[Offset(output_shape, b, out_y, out_x, oc)] =
- ActivationFunctionWithMinMax(total + bias_value,
- output_activation_min,
- output_activation_max);
- }
- }
- }
- }
- }
-}
-
-} // end namespace reference_ops
-} // end namespace tflite
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTHWISECONV_FLOAT_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/depthwiseconv_uint8.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/depthwiseconv_uint8.h
deleted file mode 100644
index 20bf83df3d8cf2590bba1f76687feb403c02b5ae..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/depthwiseconv_uint8.h
+++ /dev/null
@@ -1,297 +0,0 @@
-/* Copyright 2017 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTHWISECONV_UINT8_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTHWISECONV_UINT8_H_
-
-#include
-
-#include "fixedpoint/fixedpoint.h"
-#include "tensorflow/lite/kernels/internal/common.h"
-#include "tensorflow/lite/kernels/internal/compatibility.h"
-#include "tensorflow/lite/kernels/internal/types.h"
-
-namespace tflite {
-
-// Used in tests and template parameters to control which version of depthwise
-// convolution is called. Primarily for reference code, and specializations
-// forced in tests.
-enum class DepthwiseConvImplementation {
- // Run all tests against kUseStandardEntry even if also testing another
- // kernel, since we need to be sure that the main DepthwiseConv() function in
- // optimized_ops.h dispatches to a correctly-executing kernel.
- kNone = 0, // The "default" option: use the normal
- // DepthwiseConv kernel (entry) function.
- kUseGenericKernel, // Forced use of generic kernel.
- kUseNeon3x3, // 3x3 kernel that uses NEON when available.
- kUseNeon3x3DotProduct, // 3x3 kernel that uses dot-product enabled NEON
- // when available.
- kUseCModel3x3DotProduct, // 3x3 kernel, reference C model that is intended
- // to match overall design NEON code.
- kUseUnwound3x3DotProduct, // 3x3 kernel, reference C model with unwound loops
- // and some arrays.
- kUseIntrinsics3x3DotProduct, // 3x3 kernel using NEON intrinsics.
-};
-
-// Category of depthwise convolution output rounding.
-enum class DepthwiseConvOutputRounding {
- kNone = 0, // Invalid: specific method must be specified.
- kAwayFromZero, // Original method: exact halves rounded away from zero.
- kUpward, // Halves towards +infinity: adds 0.5 before truncate.
- // This is where a future kNearestEven would be placed.
-};
-
-// Category of depthwise convolution depth multiplication.
-enum class DepthwiseConvDepthMultiplication {
- kNoMultiplication = 0, // Depth multiplier = 1.
- kUnitInputDepth, // Input depth = 1, output depth = depth multiplier.
-};
-
-namespace reference_ops {
-namespace depthwise_conv {
-
-template
-inline int32_t DepthwiseConvRound(int32_t x, int32_t quantized_multiplier,
- int shift) {
- TFLITE_DCHECK_NE(output_rounding, DepthwiseConvOutputRounding::kNone);
- return MultiplyByQuantizedMultiplier(x, quantized_multiplier, shift);
-}
-
-template <>
-inline int32_t DepthwiseConvRound(
- int32_t x, int32_t quantized_multiplier, int shift) {
- return MultiplyByQuantizedMultiplier(x, quantized_multiplier, shift);
-}
-
-template <>
-inline int32_t DepthwiseConvRound(
- int32_t x, int32_t quantized_multiplier, int shift) {
- using gemmlowp::SaturatingRoundingDoublingHighMul;
- const int left_shift = shift > 0 ? shift : 0;
- const int right_shift = shift > 0 ? 0 : -shift;
- const int rounding_offset = right_shift > 0 ? 1 << (right_shift - 1) : 0;
- return (SaturatingRoundingDoublingHighMul(x * (1 << left_shift),
- quantized_multiplier) +
- rounding_offset) >>
- right_shift;
-}
-
-template
-struct DepthwiseConvBasicKernel {
- static inline void Run(
- const DepthwiseParams& params, const RuntimeShape& input_shape,
- const uint8_t* input_data, const RuntimeShape& filter_shape,
- const uint8_t* filter_data, const RuntimeShape& bias_shape,
- const int32_t* bias_data, const RuntimeShape& output_shape,
- uint8_t* output_data) {
- const int stride_width = params.stride_width;
- const int stride_height = params.stride_height;
- const int dilation_width_factor = params.dilation_width_factor;
- const int dilation_height_factor = params.dilation_height_factor;
- const int pad_width = params.padding_values.width;
- const int pad_height = params.padding_values.height;
- const int depth_multiplier = params.depth_multiplier;
- const int32_t output_activation_min = params.quantized_activation_min;
- const int32_t output_activation_max = params.quantized_activation_max;
- const int32_t input_offset = params.input_offset;
- const int32_t filter_offset = params.weights_offset;
- const int32_t output_offset = params.output_offset;
- const int32_t output_multiplier = params.output_multiplier;
- const int output_shift = params.output_shift;
- TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4);
-
- TFLITE_DCHECK_LE(output_activation_min, output_activation_max);
- const int batches = MatchingDim(input_shape, 0, output_shape, 0);
- const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3);
- const int input_height = input_shape.Dims(1);
- const int input_width = input_shape.Dims(2);
- const int input_depth = input_shape.Dims(3);
- const int filter_height = filter_shape.Dims(1);
- const int filter_width = filter_shape.Dims(2);
- const int output_height = output_shape.Dims(1);
- const int output_width = output_shape.Dims(2);
- TFLITE_DCHECK_EQ(output_depth, input_depth * depth_multiplier);
- TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth);
-
- for (int b = 0; b < batches; ++b) {
- for (int out_y = 0; out_y < output_height; ++out_y) {
- for (int out_x = 0; out_x < output_width; ++out_x) {
- for (int ic = 0; ic < input_depth; ++ic) {
- for (int m = 0; m < depth_multiplier; m++) {
- const int oc = m + ic * depth_multiplier;
- const int in_x_origin = (out_x * stride_width) - pad_width;
- const int in_y_origin = (out_y * stride_height) - pad_height;
- int32_t acc = 0;
- for (int filter_y = 0; filter_y < filter_height; ++filter_y) {
- for (int filter_x = 0; filter_x < filter_width; ++filter_x) {
- const int in_x =
- in_x_origin + dilation_width_factor * filter_x;
- const int in_y =
- in_y_origin + dilation_height_factor * filter_y;
- // If the location is outside the bounds of the input image,
- // use zero as a default value.
- if ((in_x >= 0) && (in_x < input_width) && (in_y >= 0) &&
- (in_y < input_height)) {
- int32_t input_val =
- input_data[Offset(input_shape, b, in_y, in_x, ic)];
- int32_t filter_val = filter_data[Offset(
- filter_shape, 0, filter_y, filter_x, oc)];
- acc += (filter_val + filter_offset) *
- (input_val + input_offset);
- }
- }
- }
- if (bias_data) {
- acc += bias_data[oc];
- }
- acc = DepthwiseConvRound(acc, output_multiplier,
- output_shift);
- acc += output_offset;
- acc = std::max(acc, output_activation_min);
- acc = std::min(acc, output_activation_max);
- output_data[Offset(output_shape, b, out_y, out_x, oc)] =
- static_cast(acc);
- }
- }
- }
- }
- }
- }
-
- // TODO(b/148596273): Reconcile reference versions, perhaps with common
- // MultiplyByQuantizedMultiplier or DepthwiseConvRound function.
- static inline void RunPerChannel(
- const DepthwiseParams& params, const RuntimeShape& input_shape,
- const int8_t* input_data, const RuntimeShape& filter_shape,
- const int8_t* filter_data, const RuntimeShape& bias_shape,
- const int32_t* bias_data, const RuntimeShape& output_shape,
- int8_t* output_data) {
- // Get parameters.
- // TODO(b/141565753): Re-introduce ScopedProfilingLabel on Micro.
- const int stride_width = params.stride_width;
- const int stride_height = params.stride_height;
- const int dilation_width_factor = params.dilation_width_factor;
- const int dilation_height_factor = params.dilation_height_factor;
- const int pad_width = params.padding_values.width;
- const int pad_height = params.padding_values.height;
- const int depth_multiplier = params.depth_multiplier;
- const int32_t input_offset = params.input_offset;
- const int32_t output_offset = params.output_offset;
- const int32_t output_activation_min = params.quantized_activation_min;
- const int32_t output_activation_max = params.quantized_activation_max;
- const int32_t* output_multiplier = params.output_multiplier_per_channel;
- const int32_t* output_shift = params.output_shift_per_channel;
-
- // Check dimensions of the tensors.
- TFLITE_DCHECK_EQ(input_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_EQ(filter_shape.DimensionsCount(), 4);
- TFLITE_DCHECK_EQ(output_shape.DimensionsCount(), 4);
-
- TFLITE_DCHECK_LE(output_activation_min, output_activation_max);
- const int batches = MatchingDim(input_shape, 0, output_shape, 0);
- const int output_depth = MatchingDim(filter_shape, 3, output_shape, 3);
- const int input_height = input_shape.Dims(1);
- const int input_width = input_shape.Dims(2);
- const int input_depth = input_shape.Dims(3);
- const int filter_height = filter_shape.Dims(1);
- const int filter_width = filter_shape.Dims(2);
- const int output_height = output_shape.Dims(1);
- const int output_width = output_shape.Dims(2);
- TFLITE_DCHECK_EQ(output_depth, input_depth * depth_multiplier);
- TFLITE_DCHECK_EQ(bias_shape.FlatSize(), output_depth);
-
- for (int batch = 0; batch < batches; ++batch) {
- for (int out_y = 0; out_y < output_height; ++out_y) {
- for (int out_x = 0; out_x < output_width; ++out_x) {
- for (int in_channel = 0; in_channel < input_depth; ++in_channel) {
- for (int m = 0; m < depth_multiplier; ++m) {
- const int output_channel = m + in_channel * depth_multiplier;
- const int in_x_origin = (out_x * stride_width) - pad_width;
- const int in_y_origin = (out_y * stride_height) - pad_height;
- int32_t acc = 0;
- for (int filter_y = 0; filter_y < filter_height; ++filter_y) {
- for (int filter_x = 0; filter_x < filter_width; ++filter_x) {
- const int in_x =
- in_x_origin + dilation_width_factor * filter_x;
- const int in_y =
- in_y_origin + dilation_height_factor * filter_y;
- // Zero padding by omitting the areas outside the image.
- const bool is_point_inside_image =
- (in_x >= 0) && (in_x < input_width) && (in_y >= 0) &&
- (in_y < input_height);
- if (is_point_inside_image) {
- int32_t input_val = input_data[Offset(
- input_shape, batch, in_y, in_x, in_channel)];
- int32_t filter_val = filter_data[Offset(
- filter_shape, 0, filter_y, filter_x, output_channel)];
- // Accumulate with 32 bits accumulator.
- // In the nudging process during model quantization, we
- // force real value of 0.0 be represented by a quantized
- // value. This guarantees that the input_offset is a int8_t,
- // even though it is represented using int32_t. int32_t +=
- // int8_t
- // * (int8_t - int8_t) so the highest value we can get from
- // each accumulation is [-127, 127] * ([-128, 127] -
- // [-128, 127]), which is [-32512, 32512]. log2(32512)
- // = 14.98, which means we can accumulate at least 2^16
- // multiplications without overflow. The accumulator is
- // applied to a filter so the accumulation logic will hold
- // as long as the filter size (filter_y * filter_x *
- // in_channel) does not exceed 2^16, which is the case in
- // all the models we have seen so far.
- acc += filter_val * (input_val + input_offset);
- }
- }
- }
- if (bias_data) {
- acc += bias_data[output_channel];
- }
- acc = DepthwiseConvRound(
- acc, output_multiplier[output_channel],
- output_shift[output_channel]);
- acc += output_offset;
- acc = std::max(acc, output_activation_min);
- acc = std::min(acc, output_activation_max);
- output_data[Offset(output_shape, batch, out_y, out_x,
- output_channel)] = static_cast(acc);
- }
- }
- }
- }
- }
- }
-};
-
-} // namespace depthwise_conv
-
-inline void DepthwiseConv(
- const DepthwiseParams& params, const RuntimeShape& input_shape,
- const uint8_t* input_data, const RuntimeShape& filter_shape,
- const uint8_t* filter_data, const RuntimeShape& bias_shape,
- const int32_t* bias_data, const RuntimeShape& output_shape,
- uint8_t* output_data) {
- return depthwise_conv::DepthwiseConvBasicKernel<
- DepthwiseConvOutputRounding::kAwayFromZero>::Run(params, input_shape,
- input_data, filter_shape,
- filter_data, bias_shape,
- bias_data, output_shape,
- output_data);
-}
-
-} // namespace reference_ops
-} // end namespace tflite
-
-#endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEPTHWISECONV_UINT8_H_
diff --git a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/dequantize.h b/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/dequantize.h
deleted file mode 100644
index b90951f96e8f20ccd3abbe6076e3d25e04fe7547..0000000000000000000000000000000000000000
--- a/components/ai/tflite_micro/ARM_CortexM55_lib/tensorflow/lite/kernels/internal/reference/dequantize.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* 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.
-==============================================================================*/
-#ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEQUANTIZE_H_
-#define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_DEQUANTIZE_H_
-
-#include
-
-#include
-
-#include "tensorflow/lite/kernels/internal/common.h"
-#include "tensorflow/lite/kernels/internal/types.h"
-
-namespace tflite {
-
-namespace reference_ops {
-
-// Dequantizes into a float without rounding.
-template
-inline void Dequantize(const tflite::DequantizationParams& op_params,
- const RuntimeShape& input_shape,
- const InputT* input_data,
- const RuntimeShape& output_shape, OutputT* output_data) {
- int32_t zero_point = op_params.zero_point;
- const double scale = op_params.scale;
- const int flat_size = MatchingFlatSize(input_shape, output_shape);
-
- for (int i = 0; i < flat_size; i++) {
- const int32_t val = input_data[i];
- const OutputT result = static_cast(scale * (val - zero_point));
- output_data[i] = result;
- }
-}
-
-// Dequantizes per-channel quantized tensor to float.
-template
-inline void PerChannelDequantize(
- const tflite::PerChannelDequantizationParams& op_params,
- const RuntimeShape& input_shape, const T* input_data,
- const RuntimeShape& output_shape, float* output_data) {
- // Ensure flat size is same.
- MatchingFlatSize(input_shape, output_shape);
-
- const int32_t* zero_point = op_params.zero_point;
- const float* scale = op_params.scale;
- const int32_t quantized_dimension = op_params.quantized_dimension;
- const int32_t num_dims = input_shape.DimensionsCount();
- const int32_t* dims_data = input_shape.DimsData();
- std::vector