├── src ├── edgeimpulse │ ├── edge-impulse-sdk │ │ ├── CMSIS │ │ │ ├── sources.txt │ │ │ ├── DSP │ │ │ │ ├── Source │ │ │ │ │ ├── CommonTables │ │ │ │ │ │ └── CommonTablesF16.c │ │ │ │ │ ├── TransformFunctions │ │ │ │ │ │ └── TransformFunctionsF16.c │ │ │ │ │ ├── BasicMathFunctions │ │ │ │ │ │ └── BasicMathFunctionsF16.c │ │ │ │ │ ├── ControllerFunctions │ │ │ │ │ │ ├── arm_pid_reset_q15.c │ │ │ │ │ │ ├── arm_pid_reset_q31.c │ │ │ │ │ │ ├── arm_pid_reset_f32.c │ │ │ │ │ │ └── arm_pid_init_f32.c │ │ │ │ │ ├── SupportFunctions │ │ │ │ │ │ ├── arm_merge_sort_init_f32.c │ │ │ │ │ │ └── arm_sort_init_f32.c │ │ │ │ │ ├── StatisticsFunctions │ │ │ │ │ │ ├── arm_entropy_f64.c │ │ │ │ │ │ ├── arm_logsumexp_dot_prod_f32.c │ │ │ │ │ │ └── arm_kullback_leibler_f64.c │ │ │ │ │ ├── DistanceFunctions │ │ │ │ │ │ ├── arm_cosine_distance_f32.c │ │ │ │ │ │ ├── arm_hamming_distance.c │ │ │ │ │ │ ├── arm_russellrao_distance.c │ │ │ │ │ │ ├── arm_jaccard_distance.c │ │ │ │ │ │ ├── arm_boolean_distance.c │ │ │ │ │ │ ├── arm_kulsinski_distance.c │ │ │ │ │ │ ├── arm_sokalsneath_distance.c │ │ │ │ │ │ ├── arm_yule_distance.c │ │ │ │ │ │ ├── arm_rogerstanimoto_distance.c │ │ │ │ │ │ ├── arm_sokalmichener_distance.c │ │ │ │ │ │ └── arm_correlation_distance_f32.c │ │ │ │ │ ├── MatrixFunctions │ │ │ │ │ │ ├── arm_mat_init_q15.c │ │ │ │ │ │ ├── arm_mat_init_q31.c │ │ │ │ │ │ └── arm_mat_init_f32.c │ │ │ │ │ ├── FilteringFunctions │ │ │ │ │ │ ├── arm_fir_lattice_init_q15.c │ │ │ │ │ │ ├── arm_fir_lattice_init_q31.c │ │ │ │ │ │ ├── arm_fir_lattice_init_f32.c │ │ │ │ │ │ └── arm_iir_lattice_init_q15.c │ │ │ │ │ └── SVMFunctions │ │ │ │ │ │ └── arm_svm_linear_init_f32.c │ │ │ │ ├── Include │ │ │ │ │ └── arm_const_structs_f16.h │ │ │ │ └── PrivateInclude │ │ │ │ │ └── arm_vec_fft.h │ │ │ ├── NN │ │ │ │ ├── Source │ │ │ │ │ ├── ReshapeFunctions │ │ │ │ │ │ └── arm_reshape_s8.c │ │ │ │ │ ├── ActivationFunctions │ │ │ │ │ │ └── arm_relu6_s8.c │ │ │ │ │ ├── ConcatenationFunctions │ │ │ │ │ │ ├── arm_concatenation_s8_w.c │ │ │ │ │ │ ├── arm_concatenation_s8_x.c │ │ │ │ │ │ ├── arm_concatenation_s8_z.c │ │ │ │ │ │ └── arm_concatenation_s8_y.c │ │ │ │ │ ├── SoftmaxFunctions │ │ │ │ │ │ └── arm_softmax_with_batch_q7.c │ │ │ │ │ └── NNSupportFunctions │ │ │ │ │ │ ├── arm_nn_accumulate_q7_to_q15.c │ │ │ │ │ │ └── arm_nn_add_q7.c │ │ │ │ └── Include │ │ │ │ │ └── arm_nn_tables.h │ │ │ └── Core │ │ │ │ └── Include │ │ │ │ └── cmsis_version.h │ │ ├── .gitignore │ │ ├── dsp │ │ │ ├── kissfft │ │ │ │ ├── README.md │ │ │ │ ├── LICENSE │ │ │ │ └── kiss_fftr.h │ │ │ ├── dct │ │ │ │ ├── README.md │ │ │ │ ├── LICENSE │ │ │ │ └── fast-dct-fft.h │ │ │ ├── memory.cpp │ │ │ ├── spectral │ │ │ │ └── spectral.hpp │ │ │ ├── speechpy │ │ │ │ └── speechpy.hpp │ │ │ └── returntypes.hpp │ │ ├── classifier │ │ │ ├── ei_run_classifier_image.h │ │ │ ├── ei_model_types.h │ │ │ └── ei_classifier_types.h │ │ ├── .mbedignore │ │ ├── LICENSE │ │ ├── sources.txt │ │ ├── README.md │ │ ├── tensorflow │ │ │ └── lite │ │ │ │ ├── string_type.h │ │ │ │ ├── micro │ │ │ │ ├── testing │ │ │ │ │ └── test_conv_model.h │ │ │ │ ├── kernels │ │ │ │ │ ├── ethosu.cpp │ │ │ │ │ ├── micro_utils.h │ │ │ │ │ ├── mli_slicers.h │ │ │ │ │ ├── activation_utils.h │ │ │ │ │ ├── floor.cpp │ │ │ │ │ ├── neg.cpp │ │ │ │ │ └── scratch_buffers.h │ │ │ │ ├── micro_time.h │ │ │ │ ├── debug_log.h │ │ │ │ ├── micro_error_reporter.h │ │ │ │ ├── micro_optional_debug_tools.h │ │ │ │ ├── compatibility.h │ │ │ │ ├── micro_string.h │ │ │ │ ├── micro_error_reporter.cpp │ │ │ │ ├── all_ops_resolver.h │ │ │ │ ├── micro_profiler.cpp │ │ │ │ ├── memory_helpers.h │ │ │ │ ├── memory_planner │ │ │ │ │ ├── linear_memory_planner.h │ │ │ │ │ └── linear_memory_planner.cpp │ │ │ │ ├── micro_time.cpp │ │ │ │ ├── all_ops_resolver.cpp │ │ │ │ ├── recording_micro_interpreter.h │ │ │ │ └── recording_simple_memory_allocator.h │ │ │ │ ├── kernels │ │ │ │ ├── internal │ │ │ │ │ ├── max.h │ │ │ │ │ ├── min.h │ │ │ │ │ ├── reference │ │ │ │ │ │ ├── neg.h │ │ │ │ │ │ ├── ceil.h │ │ │ │ │ │ ├── floor.h │ │ │ │ │ │ ├── round.h │ │ │ │ │ │ └── quantize.h │ │ │ │ │ ├── cppmath.h │ │ │ │ │ ├── optimized │ │ │ │ │ │ └── neon_check.h │ │ │ │ │ └── tensor_ctypes.h │ │ │ │ └── op_macros.h │ │ │ │ ├── core │ │ │ │ └── api │ │ │ │ │ ├── tensor_utils.h │ │ │ │ │ ├── error_reporter.cpp │ │ │ │ │ ├── tensor_utils.cpp │ │ │ │ │ ├── op_resolver.h │ │ │ │ │ ├── error_reporter.h │ │ │ │ │ └── op_resolver.cpp │ │ │ │ ├── version.h │ │ │ │ └── type_to_tflitetype.h │ │ ├── cmake │ │ │ └── zephyr │ │ │ │ └── CMakeLists.txt │ │ └── porting │ │ │ └── arduino │ │ │ └── debug_log.cpp │ └── model-parameters │ │ └── dsp_blocks.h └── data_acquisition.cpp ├── .gitignore ├── include ├── WiFiCredentials.h ├── data_acquisition.h ├── support.h ├── inference_parameter.h ├── inference.h └── README ├── custom.csv ├── CMakeListsUser.txt ├── test └── README ├── download_model.sh ├── platformio.ini └── CMakeLists.txt /src/edgeimpulse/edge-impulse-sdk/CMSIS/sources.txt: -------------------------------------------------------------------------------- 1 | Created by update_tflite.sh 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | CMakeListsPrivate.txt 3 | cmake-build-*/ 4 | ./include/WifiCredentials.h 5 | -------------------------------------------------------------------------------- /include/WiFiCredentials.h: -------------------------------------------------------------------------------- 1 | #define SSID "Alice-WLANXP" 2 | #define PASSWORD "fabneu7167" 3 | #define I2S_SERVER_URL "http://192.168.1.100:3000/" -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/.gitignore: -------------------------------------------------------------------------------- 1 | utensor/CTestTestfile.cmake 2 | utensor/cmake_install.cmake 3 | utensor/CMakeFiles/ 4 | utensor/Makefile 5 | utensor/CMakeCache.txt 6 | utensor.lib 7 | utensor/libutensor.a 8 | *.o 9 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/dsp/kissfft/README.md: -------------------------------------------------------------------------------- 1 | # KissFFT 2 | 3 | Software FFT library used for devices that do not have hardware accelerated RFFT, or where we want to use mixed-radix FFT. Based off of https://github.com/mborgerding/kissfft. 4 | -------------------------------------------------------------------------------- /custom.csv: -------------------------------------------------------------------------------- 1 | # Name, Type, SubType, Offset, Size, Flags 2 | nvs, data, nvs, 0x9000, 20K, 3 | otadata, data, ota, 0xe000, 8K, 4 | firm, app, ota_0, , 3400K, 5 | eeprom, data, 0x99, , 4K, 6 | spiffs, data, spiffs, , 444K, 7 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/classifier/ei_run_classifier_image.h: -------------------------------------------------------------------------------- 1 | #ifndef _EDGE_IMPULSE_RUN_CLASSIFIER_IMAGE_H_ 2 | #define _EDGE_IMPULSE_RUN_CLASSIFIER_IMAGE_H_ 3 | 4 | #include "ei_run_classifier.h" 5 | 6 | 7 | 8 | #endif // _EDGE_IMPULSE_RUN_CLASSIFIER_IMAGE_H_ 9 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/dsp/dct/README.md: -------------------------------------------------------------------------------- 1 | # Fast discrete cosine transform algorithms (C) 2 | 3 | DCT type 2 and type 3 algorithms based on https://www.nayuki.io/page/fast-discrete-cosine-transform-algorithms. These are modified to use KissFFT or hardware accelerated RFFT support with CMSIS-DSP. 4 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/.mbedignore: -------------------------------------------------------------------------------- 1 | utensor/CMakeFiles/ 2 | tensorflow/lite/micro/mbed/ 3 | porting/arduino/ 4 | porting/ecm3532/ 5 | porting/himax/ 6 | porting/posix/ 7 | porting/silabs/ 8 | porting/stm32-cubeai/ 9 | porting/zephyr/ 10 | classifier/ei_run_classifier_c* 11 | third_party/arc_mli_package/ 12 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/dsp/kissfft/LICENSE: -------------------------------------------------------------------------------- 1 | Revised BSD License, see COPYING for verbiage. 2 | Basically, "free to use&change, give credit where due, no guarantees" 3 | Note this license is compatible with GPL at one end of the spectrum and closed, commercial software at 4 | the other end. See http://www.fsf.org/licensing/licenses 5 | -------------------------------------------------------------------------------- /CMakeListsUser.txt: -------------------------------------------------------------------------------- 1 | macro(print_all_variables) 2 | message(STATUS "print_all_variables------------------------------------------{") 3 | get_cmake_property(_variableNames VARIABLES) 4 | foreach (_variableName ${_variableNames}) 5 | message(STATUS "${_variableName}=${${_variableName}}") 6 | endforeach() 7 | message(STATUS "print_all_variables------------------------------------------}") 8 | endmacro() 9 | -------------------------------------------------------------------------------- /include/data_acquisition.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by development on 24.01.21. 3 | // 4 | 5 | #ifndef EDGE_ESP32_DATA_ACQUISITION_H 6 | #define EDGE_ESP32_DATA_ACQUISITION_H 7 | #include 8 | #include 9 | extern WiFiClient *wifiClientI2S ; 10 | extern HTTPClient *httpClientI2S ; 11 | void sendData(WiFiClient *wifiClient, HTTPClient *httpClient, const char *url, uint8_t *bytes, size_t count); 12 | #endif //EDGE_ESP32_DATA_ACQUISITION_H 13 | -------------------------------------------------------------------------------- /test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PlatformIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PlatformIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/LICENSE: -------------------------------------------------------------------------------- 1 | Unless specifically indicated otherwise in a file, files are licensed under the Apache 2.0 license, as can be found in: LICENSE-apache-2.0.txt 2 | 3 | Folders containing files under different permissive license than Apache 2.0 are listed below. Each folder contains its own license specified for its files. 4 | 5 | * CMSIS - Apache 2.0 6 | * dsp/kissfft - BSD-3-Clause 7 | * dsp/dct - MIT 8 | * tensorflow - Apache 2.0 9 | * third_party/flatbuffers - Apache 2.0 10 | * third_party/gemmlowp - Apache 2.0 11 | * utensor - Apache 2.0 12 | -------------------------------------------------------------------------------- /src/data_acquisition.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by development on 24.01.21. 3 | // 4 | 5 | #include "data_acquisition.h" 6 | 7 | // send data to a remote address 8 | 9 | void sendData(WiFiClient *wifiClient, HTTPClient *httpClient, const char *url, uint8_t *bytes, size_t count) { 10 | // send them off to the server 11 | digitalWrite(LED_BUILTIN, HIGH); 12 | httpClient->begin(*wifiClientI2S, url); 13 | httpClient->addHeader("content-type", "application/octet-stream"); 14 | httpClient->POST(bytes, count); 15 | httpClient->end(); 16 | digitalWrite(LED_BUILTIN, LOW); 17 | } 18 | -------------------------------------------------------------------------------- /download_model.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | echo "Start Download..." 4 | curl --request GET \ 5 | --url 'https://studio.edgeimpulse.com/v1/api/18137/deployment/download?type=arduino' \ 6 | --header 'Accept: application/zip' \ 7 | --header 'x-api-key: '''${1}''\ 8 | --output arduino_model.zip 9 | unzip -q arduino_model.zip -d ./src/edgeimpulse_tmp 10 | rm -r ./src/edgeimpulse/* 11 | mv ./src/edgeimpulse_tmp/src/* ./src/edgeimpulse/ 12 | rm -r ./src/edgeimpulse_tmp/ 13 | rm ./arduino_model.zip 14 | find ./src/edgeimpulse -type f -exec touch {} + 15 | echo "Downloaded model in folder src/edgeimpulse" 16 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/sources.txt: -------------------------------------------------------------------------------- 1 | tensorflow and third_party folders based on: https://github.com/tensorflow/tensorflow/#c903b4607821a03c36c17b0befa2535c7dd0e066 2 | TensorFlow source was prepared using `make -f tensorflow/lite/micro/tools/make/Makefile generate_projects` 3 | The folders were taken from `tensorflow/lite/micro/tools/make/gen/osx_x86_64/prj/hello_world/make` 4 | These files and directories were then deleted: 5 | - `tensorflow/lite/micro/debug_log.cc` 6 | - `tensorflow/lite/micro/examples/hello_world` 7 | CMSIS-DSP based on: https://github.com/ARM-software/CMSIS_5/tree/4d378e81968c6bec5441a42885b24db7cf189bca 8 | -------------------------------------------------------------------------------- /include/support.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by development on 21.11.20. 3 | // 4 | 5 | #ifndef MS_ESP32_SUPPORT_H 6 | #define MS_ESP32_SUPPORT_H 7 | #define MYDEBUG 8 | #ifdef MYDEBUG 9 | #define MYDEBUG_CORE 10 | #define DP(x) Serial.print (x) 11 | #define DPD(x) Serial.print (x, DEC) 12 | #define DPL(x) Serial.println (x) 13 | #else 14 | #define DP(x) 15 | #define DPD(x) 16 | #define DPL(x) 17 | #endif 18 | 19 | 20 | /** 21 | * @brief Printf function uses vsnprintf and output using Arduino Serial 22 | * 23 | * @param[in] format Variable argument list 24 | */ 25 | 26 | 27 | 28 | #endif //MS_ESP32_SUPPORT_H 29 | -------------------------------------------------------------------------------- /include/inference_parameter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by development on 22.01.21. 3 | // 4 | 5 | #ifndef EDGE_ESP32_INFERENCE_PARAMETER_H 6 | #define EDGE_ESP32_INFERENCE_PARAMETER_H 7 | // If your target is limited in memory remove this macro to save 10K RAM 8 | #undef EIDSP_QUANTIZE_FILTERBANK 9 | #define EIDSP_QUANTIZE_FILTERBANK 0 10 | 11 | /** 12 | * Define the number of slices per model window. E.g. a model window of 1000 ms 13 | * with slices per model window set to 4. Results in a slice size of 250 ms. 14 | * For more info: https://docs.edgeimpulse.com/docs/continuous-audio-sampling 15 | */ 16 | #undef EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW 17 | #define EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW 5 18 | #endif //EDGE_ESP32_INFERENCE_PARAMETER_H 19 | -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [env:lolin_d32_pro] 12 | platform = espressif32 13 | board = lolin_d32_pro 14 | framework = arduino 15 | board_build.partitions = custom.csv 16 | debug_tool = esp-prog 17 | debug_init_break = tbreak setup 18 | upload_speed = 460800 19 | board_build.f_cpu = 240000000L 20 | build_flags = -DCORE_DEBUG_LEVEL=5 21 | -I ./src/edgeimpulse 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/README.md: -------------------------------------------------------------------------------- 1 | # Edge Impulse DSP and Inferencing SDK 2 | 3 | Portable library for digital signal processing and machine learning inferencing. This repository contains the device implementation in C++ for both processing and learning blocks in [Edge Impulse](https://www.edgeimpulse.com). 4 | 5 | [Documentation](https://docs.edgeimpulse.com/reference#inferencing-sdk) 6 | 7 | ## Develop locally 8 | 9 | If you want to develop locally the easiest is to grab the [example-standalone-inferencing](https://github.com/edgeimpulse/example-standalone-inferencing) (Desktop) or [example-standalone-inferencing-mbed](https://github.com/edgeimpulse/example-standalone-inferencing-mbed) (ST IoT Discovery Kit, f.e. to test CMSIS-DSP / CMSIS-NN integration) example applications, add your Edge Impulse project (use the C++ Library export option), then symlink this repository in. 10 | -------------------------------------------------------------------------------- /include/inference.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by development on 22.01.21. 3 | // 4 | 5 | #ifndef EDGE_ESP32_INFERENCE_H 6 | #define EDGE_ESP32_INFERENCE_H 7 | 8 | 9 | #include 10 | #include "support.h" 11 | 12 | 13 | /** Audio buffers, pointers and selectors */ 14 | typedef struct { 15 | signed short *buffers[2]; 16 | unsigned char buf_select; 17 | unsigned char buf_ready; 18 | unsigned int buf_count; 19 | unsigned int n_samples; 20 | } inference_t; 21 | 22 | extern inference_t inference; 23 | extern bool record_ready ; 24 | extern signed short *sampleBuffer; 25 | extern bool debug_nn ; // Set this to true to see e.g. features generated from the raw signal 26 | extern int print_results ; 27 | extern QueueHandle_t m_i2sQueue; 28 | 29 | void CaptureSamples(void *arg); 30 | void i2s_init(void); 31 | bool microphone_inference_start(uint32_t n_samples); 32 | bool microphone_inference_record(void); 33 | int microphone_audio_signal_get_data(size_t offset, size_t length, float *out_ptr); 34 | void microphone_inference_end(void); 35 | #endif //EDGE_ESP32_INFERENCE_H 36 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/string_type.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | // Abstract string. We don't want even absl at this level. 16 | #ifndef TENSORFLOW_LITE_STRING_TYPE_H_ 17 | #define TENSORFLOW_LITE_STRING_TYPE_H_ 18 | 19 | #include 20 | 21 | namespace tflite { 22 | 23 | using std::string; 24 | 25 | } // namespace tflite 26 | 27 | #endif // TENSORFLOW_LITE_STRING_TYPE_H_ 28 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/testing/test_conv_model.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_TESTING_TEST_CONV_MODEL_H_ 17 | #define TENSORFLOW_LITE_MICRO_TESTING_TEST_CONV_MODEL_H_ 18 | 19 | // See generate_test_models.py for updating the contents of this model: 20 | extern const unsigned char kTestConvModelData[]; 21 | extern const unsigned int kTestConvModelDataSize; 22 | 23 | #endif // TENSORFLOW_LITE_MICRO_TESTING_TEST_CONV_MODEL_H_ 24 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # !!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE 2 | # https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags 3 | # 4 | # If you need to override existing CMake configuration or add extra, 5 | # please create `CMakeListsUser.txt` in the root of project. 6 | # The `CMakeListsUser.txt` will not be overwritten by PlatformIO. 7 | 8 | cmake_minimum_required(VERSION 3.13) 9 | set(CMAKE_SYSTEM_NAME Generic) 10 | set(CMAKE_C_COMPILER_WORKS 1) 11 | set(CMAKE_CXX_COMPILER_WORKS 1) 12 | 13 | project("edge_esp32" C CXX) 14 | 15 | include(CMakeListsPrivate.txt) 16 | 17 | if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/CMakeListsUser.txt) 18 | include(CMakeListsUser.txt) 19 | endif() 20 | 21 | add_custom_target( 22 | Production ALL 23 | COMMAND platformio -c clion run "$<$>:-e${CMAKE_BUILD_TYPE}>" 24 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 25 | ) 26 | 27 | add_custom_target( 28 | Debug ALL 29 | COMMAND platformio -c clion run --target debug "$<$>:-e${CMAKE_BUILD_TYPE}>" 30 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} 31 | ) 32 | 33 | add_executable(Z_DUMMY_TARGET ${SRC_LIST}) 34 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/kernels/internal/max.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_ 17 | 18 | #include 19 | 20 | namespace tflite { 21 | 22 | // Patched by Edge Impulse, remove std::fmax 23 | template 24 | inline T TfLiteMax(const T& x, const T& y) { 25 | return std::max(x, y); 26 | } 27 | 28 | } // namespace tflite 29 | 30 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_MAX_H_ 31 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/kernels/internal/min.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_MIN_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_MIN_H_ 17 | 18 | #include 19 | 20 | namespace tflite { 21 | 22 | // Patched by Edge Impulse, remove std::fmin 23 | template 24 | inline T TfLiteMin(const T& x, const T& y) { 25 | return std::min(x, y); 26 | } 27 | 28 | } // namespace tflite 29 | 30 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_MIN_H_ 31 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/core/api/tensor_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_CORE_API_TENSOR_UTILS_H_ 17 | #define TENSORFLOW_LITE_CORE_API_TENSOR_UTILS_H_ 18 | 19 | #include "edge-impulse-sdk/tensorflow/lite/c/common.h" 20 | 21 | namespace tflite { 22 | 23 | // Resets a variable tensor to the default value. 24 | TfLiteStatus ResetVariableTensor(TfLiteTensor* tensor); 25 | 26 | } // namespace tflite 27 | 28 | #endif // TENSORFLOW_LITE_CORE_API_TENSOR_UTILS_H_ 29 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/kernels/ethosu.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // 17 | // This is a stub file for non-Ethos platforms 18 | // 19 | #include "edge-impulse-sdk/tensorflow/lite/c/common.h" 20 | 21 | namespace tflite { 22 | namespace ops { 23 | namespace micro { 24 | namespace custom { 25 | TfLiteRegistration* Register_ETHOSU() { return nullptr; } 26 | 27 | const char* GetString_ETHOSU() { return ""; } 28 | 29 | } // namespace custom 30 | } // namespace micro 31 | } // namespace ops 32 | } // namespace tflite 33 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/cmake/zephyr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.1) 2 | 3 | set(CMAKE_CXX_STANDARD 11) 4 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 5 | 6 | set(EI_SDK_FOLDER ../../) 7 | 8 | include(${EI_SDK_FOLDER}/cmake/utils.cmake) 9 | 10 | target_include_directories(app PRIVATE 11 | ${EI_SDK_FOLDER} 12 | ${EI_SDK_FOLDER}/third_party/ruy 13 | ${EI_SDK_FOLDER}/third_party/gemmlowp 14 | ${EI_SDK_FOLDER}/third_party/flatbuffers/include 15 | ${EI_SDK_FOLDER}/third_party 16 | ${EI_SDK_FOLDER}/tensorflow 17 | ${EI_SDK_FOLDER}/dsp 18 | ${EI_SDK_FOLDER}/classifier 19 | ${EI_SDK_FOLDER}/anomaly 20 | ${EI_SDK_FOLDER}/CMSIS/NN/Include 21 | ${EI_SDK_FOLDER}/CMSIS/DSP/PrivateInclude 22 | ${EI_SDK_FOLDER}/CMSIS/DSP/Include 23 | ${EI_SDK_FOLDER}/CMSIS/Core/Include 24 | ) 25 | 26 | RECURSIVE_FIND_FILE(SOURCE_FILES "${EI_SDK_FOLDER}" "*.cpp") 27 | RECURSIVE_FIND_FILE(CC_FILES "${EI_SDK_FOLDER}" "*.cc") 28 | RECURSIVE_FIND_FILE(S_FILES "${EI_SDK_FOLDER}" "*.s") 29 | RECURSIVE_FIND_FILE(C_FILES "${EI_SDK_FOLDER}" "*.c") 30 | list(APPEND SOURCE_FILES ${S_FILES}) 31 | list(APPEND SOURCE_FILES ${C_FILES}) 32 | list(APPEND SOURCE_FILES ${CC_FILES}) 33 | 34 | target_sources(app PRIVATE ${SOURCE_FILES}) 35 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/dsp/dct/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Project Nayuki. (MIT License) 2 | https://www.nayuki.io/page/fast-discrete-cosine-transform-algorithms 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | the Software, and to permit persons to whom the Software is furnished to do so, 9 | subject to the following conditions: 10 | - The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | - The Software is provided "as is", without warranty of any kind, express or 13 | implied, including but not limited to the warranties of merchantability, 14 | fitness for a particular purpose and noninfringement. In no event shall the 15 | authors or copyright holders be liable for any claim, damages or other 16 | liability, whether in an action of contract, tort or otherwise, arising from, 17 | out of or in connection with the Software or the use or other dealings in the 18 | Software. 19 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/micro_time.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_MICRO_TIME_H_ 16 | #define TENSORFLOW_LITE_MICRO_MICRO_TIME_H_ 17 | 18 | #include 19 | 20 | namespace tflite { 21 | 22 | // These functions should be implemented by each target platform, and provide an 23 | // accurate tick count along with how many ticks there are per second. 24 | int32_t ticks_per_second(); 25 | 26 | // Return time in ticks. The meaning of a tick varies per platform. 27 | int32_t GetCurrentTimeTicks(); 28 | 29 | } // namespace tflite 30 | 31 | #endif // TENSORFLOW_LITE_MICRO_MICRO_TIME_H_ 32 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/debug_log.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_DEBUG_LOG_H_ 16 | #define TENSORFLOW_LITE_MICRO_DEBUG_LOG_H_ 17 | 18 | // This function should be implemented by each target platform, and provide a 19 | // way for strings to be output to some text stream. For more information, see 20 | // tensorflow/lite/micro/debug_log.cc. 21 | #if defined(__cplusplus) && EI_C_LINKAGE == 1 22 | extern "C" void DebugLog(const char* s); 23 | #else 24 | void DebugLog(const char* s); 25 | #endif // defined(__cplusplus) && EI_C_LINKAGE == 1 26 | 27 | #endif // TENSORFLOW_LITE_MICRO_DEBUG_LOG_H_ 28 | 29 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/dsp/memory.cpp: -------------------------------------------------------------------------------- 1 | /* Edge Impulse inferencing library 2 | * Copyright (c) 2021 EdgeImpulse Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include "memory.hpp" 24 | 25 | size_t ei_memory_in_use = 0; 26 | size_t ei_memory_peak_use = 0; 27 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/dsp/kissfft/kiss_fftr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003-2004, Mark Borgerding. All rights reserved. 3 | * This file is part of KISS FFT - https://github.com/mborgerding/kissfft 4 | * 5 | * SPDX-License-Identifier: BSD-3-Clause 6 | * See COPYING file for more information. 7 | */ 8 | 9 | #ifndef KISS_FTR_H 10 | #define KISS_FTR_H 11 | 12 | #include "kiss_fft.h" 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | 18 | /* 19 | 20 | Real optimized version can save about 45% cpu time vs. complex fft of a real seq. 21 | 22 | 23 | 24 | */ 25 | 26 | typedef struct kiss_fftr_state *kiss_fftr_cfg; 27 | 28 | 29 | kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem, size_t * memallocated = NULL); 30 | /* 31 | nfft must be even 32 | 33 | If you don't care to allocate space, use mem = lenmem = NULL 34 | */ 35 | 36 | 37 | void kiss_fftr(kiss_fftr_cfg cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata); 38 | /* 39 | input timedata has nfft scalar points 40 | output freqdata has nfft/2+1 complex points 41 | */ 42 | 43 | void kiss_fftri(kiss_fftr_cfg cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata); 44 | /* 45 | input freqdata has nfft/2+1 complex points 46 | output timedata has nfft scalar points 47 | */ 48 | 49 | #define kiss_fftr_free KISS_FFT_FREE 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | #endif 55 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/version.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_VERSION_H_ 16 | #define TENSORFLOW_LITE_VERSION_H_ 17 | 18 | #include "edge-impulse-sdk/tensorflow/core/public/version.h" 19 | 20 | // The version number of the Schema. Ideally all changes will be backward 21 | // compatible. If that ever changes, we must ensure that version is the first 22 | // entry in the new tflite root so that we can see that version is not 1. 23 | #define TFLITE_SCHEMA_VERSION (3) 24 | 25 | // TensorFlow Lite Runtime version. 26 | // This value is currently shared with that of TensorFlow. 27 | #define TFLITE_VERSION_STRING TF_VERSION_STRING 28 | 29 | #endif // TENSORFLOW_LITE_VERSION_H_ 30 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/micro_error_reporter.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_MICRO_ERROR_REPORTER_H_ 16 | #define TENSORFLOW_LITE_MICRO_MICRO_ERROR_REPORTER_H_ 17 | 18 | #include 19 | 20 | #include "edge-impulse-sdk/tensorflow/lite/core/api/error_reporter.h" 21 | #include "edge-impulse-sdk/tensorflow/lite/micro/compatibility.h" 22 | 23 | namespace tflite { 24 | 25 | class MicroErrorReporter : public ErrorReporter { 26 | public: 27 | ~MicroErrorReporter() override {} 28 | int Report(const char* format, va_list args) override; 29 | 30 | private: 31 | TF_LITE_REMOVE_VIRTUAL_DELETE 32 | }; 33 | 34 | } // namespace tflite 35 | 36 | #endif // TENSORFLOW_LITE_MICRO_MICRO_ERROR_REPORTER_H_ 37 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/CommonTables/CommonTablesF16.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: CommonTables.c 6 | * Description: Combination of all common table source files. 7 | * 8 | * $Date: 08. January 2020 9 | * $Revision: V1.1.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2019-2020 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "arm_common_tables_f16.c" 32 | #include "arm_const_structs_f16.c" 33 | #include "arm_mve_tables_f16.c" 34 | 35 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 36 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/core/api/error_reporter.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #include "edge-impulse-sdk/tensorflow/lite/core/api/error_reporter.h" 16 | #include 17 | 18 | namespace tflite { 19 | 20 | int ErrorReporter::Report(const char* format, ...) { 21 | va_list args; 22 | va_start(args, format); 23 | int code = Report(format, args); 24 | va_end(args); 25 | return code; 26 | } 27 | 28 | // TODO(aselle): Make the name of ReportError on context the same, so 29 | // we can use the ensure functions w/o a context and w/ a reporter. 30 | int ErrorReporter::ReportError(void*, const char* format, ...) { 31 | va_list args; 32 | va_start(args, format); 33 | int code = Report(format, args); 34 | va_end(args); 35 | return code; 36 | } 37 | 38 | } // namespace tflite 39 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/kernels/micro_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License. 11 | ==============================================================================*/ 12 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_MICRO_UTILS_H_ 13 | #define TENSORFLOW_LITE_MICRO_KERNELS_MICRO_UTILS_H_ 14 | namespace tflite { 15 | namespace ops { 16 | namespace micro { 17 | 18 | // Same as gtl::Greater but defined here to reduce dependencies and 19 | // binary size for micro environment. 20 | struct Greater { 21 | template 22 | bool operator()(const T& x, const T& y) const { 23 | return x > y; 24 | } 25 | }; 26 | 27 | struct Less { 28 | template 29 | bool operator()(const T& x, const T& y) const { 30 | return x < y; 31 | } 32 | }; 33 | 34 | } // namespace micro 35 | } // namespace ops 36 | } // namespace tflite 37 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_MICRO_UTILS_H_ 38 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/dsp/spectral/spectral.hpp: -------------------------------------------------------------------------------- 1 | /* Edge Impulse inferencing library 2 | * Copyright (c) 2021 EdgeImpulse Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef _EIDSP_SPECTRAL_SPECTRAL_H_ 24 | #define _EIDSP_SPECTRAL_SPECTRAL_H_ 25 | 26 | #include "../config.hpp" 27 | #include "processing.hpp" 28 | #include "feature.hpp" 29 | 30 | #endif // _EIDSP_SPECTRAL_SPECTRAL_H_ 31 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/TransformFunctions/TransformFunctionsF16.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: TransformFunctionsF16.c 6 | * Description: Combination of all transform function f16 source files. 7 | * 8 | * $Date: 20. April 2020 9 | * $Revision: V1.0.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "arm_cfft_f16.c" 32 | #include "arm_cfft_init_f16.c" 33 | #include "arm_cfft_radix2_f16.c" 34 | #include "arm_cfft_radix4_f16.c" 35 | 36 | 37 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 38 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/dsp/speechpy/speechpy.hpp: -------------------------------------------------------------------------------- 1 | /* Edge Impulse inferencing library 2 | * Copyright (c) 2021 EdgeImpulse Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef _EIDSP_SPEECHPY_SPEECHPY_H_ 24 | #define _EIDSP_SPEECHPY_SPEECHPY_H_ 25 | 26 | #include "../config.hpp" 27 | #include "feature.hpp" 28 | #include "functions.hpp" 29 | #include "processing.hpp" 30 | 31 | #endif // _EIDSP_SPEECHPY_SPEECHPY_H_ 32 | -------------------------------------------------------------------------------- /include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/kernels/internal/reference/neg.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_NEG_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_NEG_H_ 17 | 18 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/types.h" 19 | 20 | namespace tflite { 21 | 22 | namespace reference_ops { 23 | 24 | template 25 | inline void Negate(const RuntimeShape& input_shape, const T* input_data, 26 | const RuntimeShape& output_shape, T* output_data) { 27 | const int flat_size = MatchingFlatSize(input_shape, output_shape); 28 | 29 | for (int i = 0; i < flat_size; ++i) { 30 | output_data[i] = -input_data[i]; 31 | } 32 | } 33 | 34 | } // namespace reference_ops 35 | } // namespace tflite 36 | 37 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_NEG_H_ 38 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/kernels/internal/reference/ceil.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CEIL_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CEIL_H_ 17 | 18 | #include 19 | 20 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/types.h" 21 | 22 | namespace tflite { 23 | 24 | namespace reference_ops { 25 | 26 | inline void Ceil(const RuntimeShape& input_shape, const float* input_data, 27 | const RuntimeShape& output_shape, float* output_data) { 28 | const int flat_size = MatchingFlatSize(input_shape, output_shape); 29 | 30 | for (int i = 0; i < flat_size; ++i) { 31 | output_data[i] = std::ceil(input_data[i]); 32 | } 33 | } 34 | 35 | } // namespace reference_ops 36 | } // namespace tflite 37 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_CEIL_H_ 38 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/micro_optional_debug_tools.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | // Optional debugging functionality. For small sized binaries, these are not 16 | // needed. 17 | #ifndef TENSORFLOW_LITE_MICRO_MICRO_OPTIONAL_DEBUG_TOOLS_H_ 18 | #define TENSORFLOW_LITE_MICRO_MICRO_OPTIONAL_DEBUG_TOOLS_H_ 19 | 20 | #include "edge-impulse-sdk/tensorflow/lite/micro/micro_interpreter.h" 21 | 22 | namespace tflite { 23 | // Helper function to print model flatbuffer data. This function is not called 24 | // by default. Hence it's not linked in to the final binary code. 25 | void PrintModelData(const Model* model, ErrorReporter* error_reporter); 26 | // Prints a dump of what tensors and what nodes are in the interpreter. 27 | void PrintInterpreterState(MicroInterpreter* interpreter); 28 | } // namespace tflite 29 | 30 | #endif // TENSORFLOW_LITE_MICRO_MICRO_OPTIONAL_DEBUG_TOOLS_H_ 31 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/compatibility.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_COMPATIBILITY_H_ 16 | #define TENSORFLOW_LITE_MICRO_COMPATIBILITY_H_ 17 | 18 | // C++ will automatically create class-specific delete operators for virtual 19 | // objects, which by default call the global delete function. For embedded 20 | // applications we want to avoid this, and won't be calling new/delete on these 21 | // objects, so we need to override the default implementation with one that does 22 | // nothing to avoid linking in ::delete(). 23 | // This macro needs to be included in all subclasses of a virtual base class in 24 | // the private section. 25 | #ifdef TF_LITE_STATIC_MEMORY 26 | #define TF_LITE_REMOVE_VIRTUAL_DELETE \ 27 | void operator delete(void* p) {} 28 | #else 29 | #define TF_LITE_REMOVE_VIRTUAL_DELETE 30 | #endif 31 | 32 | #endif // TENSORFLOW_LITE_MICRO_COMPATIBILITY_H_ 33 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/kernels/internal/reference/floor.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_H_ 17 | 18 | #include 19 | 20 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/types.h" 21 | 22 | namespace tflite { 23 | 24 | namespace reference_ops { 25 | 26 | inline void Floor(const RuntimeShape& input_shape, const float* input_data, 27 | const RuntimeShape& output_shape, float* output_data) { 28 | const int flat_size = MatchingFlatSize(input_shape, output_shape); 29 | 30 | for (int i = 0; i < flat_size; i++) { 31 | int offset = i; 32 | output_data[offset] = std::floor(input_data[offset]); 33 | } 34 | } 35 | 36 | } // namespace reference_ops 37 | } // namespace tflite 38 | 39 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_FLOOR_H_ 40 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/BasicMathFunctions/BasicMathFunctionsF16.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: BasicMathFunctionsF16.c 6 | * Description: Combination of all basic math function f16 source files. 7 | * 8 | * $Date: 20. April 2020 9 | * $Revision: V1.1.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2019-2020 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "arm_abs_f16.c" 32 | #include "arm_add_f16.c" 33 | #include "arm_dot_prod_f16.c" 34 | #include "arm_mult_f16.c" 35 | #include "arm_negate_f16.c" 36 | #include "arm_offset_f16.c" 37 | #include "arm_scale_f16.c" 38 | #include "arm_sub_f16.c" 39 | 40 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 41 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/kernels/internal/cppmath.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_CPPMATH_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_CPPMATH_H_ 17 | 18 | #include 19 | 20 | namespace tflite { 21 | 22 | #if defined(TF_LITE_USE_GLOBAL_CMATH_FUNCTIONS) || \ 23 | (defined(__ANDROID__) && !defined(__NDK_MAJOR__)) || defined(ARDUINO) || \ 24 | defined(__ZEPHYR__) 25 | #define TF_LITE_GLOBAL_STD_PREFIX 26 | #else 27 | #define TF_LITE_GLOBAL_STD_PREFIX std 28 | #endif 29 | 30 | #define DECLARE_STD_GLOBAL_SWITCH1(tf_name, std_name) \ 31 | template \ 32 | inline T tf_name(const T x) { \ 33 | return TF_LITE_GLOBAL_STD_PREFIX::std_name(x); \ 34 | } 35 | 36 | DECLARE_STD_GLOBAL_SWITCH1(TfLiteRound, round); 37 | 38 | } // namespace tflite 39 | 40 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_CPPMATH_H_ 41 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/micro_string.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_MICRO_STRING_H_ 16 | #define TENSORFLOW_LITE_MICRO_MICRO_STRING_H_ 17 | 18 | #include 19 | 20 | // Implements simple string formatting for numeric types. Returns the number of 21 | // bytes written to output. 22 | extern "C" { 23 | // Functionally equivalent to vsnprintf, trimmed down for TFLite Micro. 24 | // MicroSnprintf() is implemented using MicroVsnprintf(). 25 | int MicroVsnprintf(char* output, int len, const char* format, va_list args); 26 | // Functionally equavalent to snprintf, trimmed down for TFLite Micro. 27 | // For example, MicroSnprintf(buffer, 10, "int %d", 10) will put the string 28 | // "int 10" in the buffer. 29 | // Floating point values are logged in exponent notation (1.XXX*2^N). 30 | int MicroSnprintf(char* output, int len, const char* format, ...); 31 | } 32 | 33 | #endif // TENSORFLOW_LITE_MICRO_MICRO_STRING_H_ 34 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/micro_error_reporter.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "edge-impulse-sdk/tensorflow/lite/micro/micro_error_reporter.h" 17 | 18 | #include 19 | 20 | #ifndef TF_LITE_STRIP_ERROR_STRINGS 21 | #include "edge-impulse-sdk/tensorflow/lite/micro/debug_log.h" 22 | #include "edge-impulse-sdk/tensorflow/lite/micro/micro_string.h" 23 | #endif 24 | 25 | namespace tflite { 26 | 27 | int MicroErrorReporter::Report(const char* format, va_list args) { 28 | #ifndef TF_LITE_STRIP_ERROR_STRINGS 29 | // Only pulling in the implementation of this function for builds where we 30 | // expect to make use of it to be extra cautious about not increasing the code 31 | // size. 32 | static constexpr int kMaxLogLen = 256; 33 | char log_buffer[kMaxLogLen]; 34 | MicroVsnprintf(log_buffer, kMaxLogLen, format, args); 35 | DebugLog(log_buffer); 36 | DebugLog("\r\n"); 37 | #endif 38 | return 0; 39 | } 40 | 41 | } // namespace tflite 42 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/kernels/internal/optimized/neon_check.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_ 17 | 18 | #if defined(__ARM_NEON__) || defined(__ARM_NEON) 19 | #define USE_NEON 20 | #include 21 | #endif 22 | 23 | #if defined __GNUC__ && defined __SSE4_1__ && !defined TF_LITE_DISABLE_X86_NEON 24 | #define USE_NEON 25 | #include "NEON_2_SSE.h" 26 | #endif 27 | 28 | // NEON_OR_PORTABLE(SomeFunc, args) calls NeonSomeFunc(args) if USE_NEON is 29 | // defined, PortableSomeFunc(args) otherwise. 30 | #ifdef USE_NEON 31 | // Always use Neon code 32 | #define NEON_OR_PORTABLE(funcname, ...) Neon##funcname(__VA_ARGS__) 33 | 34 | #else 35 | // No NEON available: Use Portable code 36 | #define NEON_OR_PORTABLE(funcname, ...) Portable##funcname(__VA_ARGS__) 37 | 38 | #endif // defined(USE_NEON) 39 | 40 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_OPTIMIZED_NEON_CHECK_H_ 41 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/all_ops_resolver.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License. 11 | ==============================================================================*/ 12 | #ifndef TENSORFLOW_LITE_MICRO_ALL_OPS_RESOLVER_H_ 13 | #define TENSORFLOW_LITE_MICRO_ALL_OPS_RESOLVER_H_ 14 | 15 | #include "edge-impulse-sdk/tensorflow/lite/micro/compatibility.h" 16 | #include "edge-impulse-sdk/tensorflow/lite/micro/micro_mutable_op_resolver.h" 17 | 18 | namespace tflite { 19 | 20 | // The magic number in the template parameter is the maximum number of ops that 21 | // can be added to AllOpsResolver. It can be increased if needed. And most 22 | // applications that care about the memory footprint will want to directly use 23 | // MicroMutableOpResolver and have an application specific template parameter. 24 | // The examples directory has sample code for this. 25 | class AllOpsResolver : public MicroMutableOpResolver<128> { 26 | public: 27 | AllOpsResolver(); 28 | 29 | private: 30 | TF_LITE_REMOVE_VIRTUAL_DELETE 31 | }; 32 | 33 | } // namespace tflite 34 | 35 | #endif // TENSORFLOW_LITE_MICRO_ALL_OPS_RESOLVER_H_ 36 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/dsp/dct/fast-dct-fft.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Fast discrete cosine transform algorithms (C) 3 | * 4 | * Copyright (c) 2018 Project Nayuki. (MIT License) 5 | * https://www.nayuki.io/page/fast-discrete-cosine-transform-algorithms 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 8 | * this software and associated documentation files (the "Software"), to deal in 9 | * the Software without restriction, including without limitation the rights to 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 11 | * the Software, and to permit persons to whom the Software is furnished to do so, 12 | * subject to the following conditions: 13 | * - The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * - The Software is provided "as is", without warranty of any kind, express or 16 | * implied, including but not limited to the warranties of merchantability, 17 | * fitness for a particular purpose and noninfringement. In no event shall the 18 | * authors or copyright holders be liable for any claim, damages or other 19 | * liability, whether in an action of contract, tort or otherwise, arising from, 20 | * out of or in connection with the Software or the use or other dealings in the 21 | * Software. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include "../kissfft/kiss_fft.h" 29 | 30 | namespace ei { 31 | namespace dct { 32 | 33 | int transform(float vector[], size_t len); 34 | int inverse_transform(float vector[], size_t len); 35 | 36 | } // namespace dct 37 | } // namespace ei 38 | -------------------------------------------------------------------------------- /src/edgeimpulse/model-parameters/dsp_blocks.h: -------------------------------------------------------------------------------- 1 | /* Generated by Edge Impulse 2 | * 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy 4 | * of this software and associated documentation files (the "Software"), to deal 5 | * in the Software without restriction, including without limitation the rights 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | * copies of the Software, and to permit persons to whom the Software is 8 | * furnished to do so, subject to the following conditions: 9 | * 10 | * The above copyright notice and this permission notice shall be included in 11 | * all copies or substantial portions of the Software. 12 | * 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | * SOFTWARE. 20 | */ 21 | 22 | #ifndef _EI_CLASSIFIER_DSP_BLOCKS_H_ 23 | #define _EI_CLASSIFIER_DSP_BLOCKS_H_ 24 | 25 | #include "model-parameters/model_metadata.h" 26 | #include "edge-impulse-sdk/classifier/ei_run_dsp.h" 27 | #include "edge-impulse-sdk/classifier/ei_model_types.h" 28 | 29 | const size_t ei_dsp_blocks_size = 1; 30 | ei_model_dsp_t ei_dsp_blocks[ei_dsp_blocks_size] = { 31 | { // DSP block 3 32 | 697, 33 | &extract_mfcc_features, 34 | (void*)&ei_dsp_config_3 35 | } 36 | }; 37 | 38 | #endif // _EI_CLASSIFIER_DSP_BLOCKS_H_ -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/NN/Source/ReshapeFunctions/arm_reshape_s8.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2019 Arm Limited or its affiliates. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /* ---------------------------------------------------------------------- 20 | * Project: CMSIS NN Library 21 | * Title: arm_reshape_s8.c 22 | * Description: Reshape a s8 vector 23 | * 24 | * $Date: September 2019 25 | * $Revision: V.1.0.0 26 | * 27 | * Target Processor: Cortex-M cores 28 | * 29 | * -------------------------------------------------------------------- */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/NN/Include/arm_nnfunctions.h" 32 | 33 | /** 34 | * @ingroup groupNN 35 | */ 36 | 37 | /** 38 | * @addtogroup Reshape 39 | * @{ 40 | */ 41 | 42 | /** 43 | * Basic s8 reshape function. 44 | * 45 | * Refer header file for details. 46 | * 47 | */ 48 | 49 | void arm_reshape_s8(const int8_t *input, 50 | int8_t *output, 51 | const uint32_t total_size) 52 | { 53 | memcpy(output, input, total_size); 54 | } 55 | 56 | /** 57 | * @} end of Reshape group 58 | */ 59 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/micro_profiler.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "edge-impulse-sdk/tensorflow/lite/micro/micro_profiler.h" 17 | 18 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/compatibility.h" 19 | #include "edge-impulse-sdk/tensorflow/lite/micro/micro_time.h" 20 | 21 | namespace tflite { 22 | 23 | MicroProfiler::MicroProfiler(tflite::ErrorReporter* reporter) 24 | : reporter_(reporter) {} 25 | 26 | uint32_t MicroProfiler::BeginEvent(const char* tag, EventType event_type, 27 | int64_t event_metadata1, 28 | int64_t event_metadata2) { 29 | start_time_ = GetCurrentTimeTicks(); 30 | TFLITE_DCHECK(tag != nullptr); 31 | event_tag_ = tag; 32 | return 0; 33 | } 34 | 35 | void MicroProfiler::EndEvent(uint32_t event_handle) { 36 | int32_t end_time = GetCurrentTimeTicks(); 37 | TF_LITE_REPORT_ERROR(reporter_, "%s took %d cycles\n", event_tag_, 38 | end_time - start_time_); 39 | } 40 | 41 | } // namespace tflite 42 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/porting/arduino/debug_log.cpp: -------------------------------------------------------------------------------- 1 | /* Edge Impulse inferencing library 2 | * Copyright (c) 2021 EdgeImpulse Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #include "../ei_classifier_porting.h" 24 | #if EI_PORTING_ARDUINO == 1 25 | 26 | #include "edge-impulse-sdk/tensorflow/lite/micro/debug_log.h" 27 | #include 28 | #include 29 | 30 | // On mbed platforms, we set up a serial port and write to it for debug logging. 31 | #if defined(__cplusplus) && EI_C_LINKAGE == 1 32 | extern "C" 33 | #endif // defined(__cplusplus) && EI_C_LINKAGE == 1 34 | void DebugLog(const char* s) { 35 | ei_printf("%s", s); 36 | } 37 | 38 | #endif // EI_PORTING_ARDUINO 39 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/Core/Include/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.4 5 | * @date 23. July 2019 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2019 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 4U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/NN/Source/ActivationFunctions/arm_relu6_s8.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2019 Arm Limited or its affiliates. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /* ---------------------------------------------------------------------- 20 | * Project: CMSIS NN Library 21 | * Title: arm_relu6_s8.c 22 | * Description: Basic s8 version of ReLU6 23 | * 24 | * $Date: Spetember 2019 25 | * $Revision: V.1.0.0 26 | * 27 | * Target Processor: Cortex-M cores 28 | * 29 | * -------------------------------------------------------------------- */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | #include "edge-impulse-sdk/CMSIS/NN/Include/arm_nnfunctions.h" 33 | 34 | /** 35 | * @ingroup groupNN 36 | */ 37 | 38 | /** 39 | * @addtogroup Acti 40 | * @{ 41 | */ 42 | 43 | /* 44 | * Basic ReLU6 function 45 | * 46 | * Refer to header file for details. 47 | * 48 | */ 49 | 50 | void arm_relu6_s8(q7_t *data, uint16_t size) 51 | { 52 | int32_t i; 53 | 54 | for (i = 0; i < size; i++) 55 | { 56 | int32_t ip = data[i]; 57 | 58 | ip = MAX(ip, 0); 59 | data[i] = MIN(ip, 6); 60 | } 61 | } 62 | 63 | /** 64 | * @} end of Acti group 65 | */ 66 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/classifier/ei_model_types.h: -------------------------------------------------------------------------------- 1 | /* Edge Impulse inferencing library 2 | * Copyright (c) 2021 EdgeImpulse Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef _EDGE_IMPULSE_MODEL_TYPES_H_ 24 | #define _EDGE_IMPULSE_MODEL_TYPES_H_ 25 | 26 | #include 27 | #include "edge-impulse-sdk/dsp/numpy.hpp" 28 | 29 | typedef struct { 30 | size_t n_output_features; 31 | int (*extract_fn)(ei::signal_t *signal, ei::matrix_t *output_matrix, void *config, const float frequency); 32 | void *config; 33 | } ei_model_dsp_t; 34 | 35 | typedef struct { 36 | size_t n_output_features; 37 | int (*extract_fn)(ei::signal_i16_t *signal, ei::matrix_i32_t *output_matrix, void *config, const float frequency); 38 | void *config; 39 | } ei_model_dsp_i16_t; 40 | 41 | #endif // _EDGE_IMPULSE_MODEL_TYPES_H_ 42 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/core/api/tensor_utils.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "edge-impulse-sdk/tensorflow/lite/core/api/tensor_utils.h" 17 | 18 | #include 19 | 20 | #include "edge-impulse-sdk/tensorflow/lite/c/common.h" 21 | 22 | namespace tflite { 23 | 24 | TfLiteStatus ResetVariableTensor(TfLiteTensor* tensor) { 25 | if (!tensor->is_variable) { 26 | return kTfLiteOk; 27 | } 28 | // TODO(b/115961645): Implement - If a variable tensor has a buffer, reset it 29 | // to the value of the buffer. 30 | int value = 0; 31 | if (tensor->type == kTfLiteInt8) { 32 | value = tensor->params.zero_point; 33 | } 34 | // TODO(b/139446230): Provide a platform header to better handle these 35 | // specific scenarios. 36 | #if __ANDROID__ || defined(__x86_64__) || defined(__i386__) || \ 37 | defined(__i386) || defined(__x86__) || defined(__X86__) || \ 38 | defined(_X86_) || defined(_M_IX86) || defined(_M_X64) 39 | memset(tensor->data.raw, value, tensor->bytes); 40 | #else 41 | char* raw_ptr = tensor->data.raw; 42 | for (size_t i = 0; i < tensor->bytes; ++i) { 43 | *raw_ptr = value; 44 | raw_ptr++; 45 | } 46 | #endif 47 | return kTfLiteOk; 48 | } 49 | 50 | } // namespace tflite 51 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/kernels/internal/tensor_ctypes.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_CTYPES_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_CTYPES_H_ 17 | 18 | #include "edge-impulse-sdk/tensorflow/lite/c/common.h" 19 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/types.h" 20 | 21 | namespace tflite { 22 | 23 | template 24 | inline T* GetTensorData(TfLiteTensor* tensor) { 25 | return tensor != nullptr ? reinterpret_cast(tensor->data.raw) : nullptr; 26 | } 27 | 28 | template 29 | inline const T* GetTensorData(const TfLiteTensor* tensor) { 30 | return tensor != nullptr ? reinterpret_cast(tensor->data.raw) 31 | : nullptr; 32 | } 33 | 34 | inline RuntimeShape GetTensorShape(const TfLiteTensor* tensor) { 35 | if (tensor == nullptr) { 36 | return RuntimeShape(); 37 | } 38 | 39 | TfLiteIntArray* dims = tensor->dims; 40 | const int dims_size = dims->size; 41 | const int32_t* dims_data = reinterpret_cast(dims->data); 42 | return RuntimeShape(dims_size, dims_data); 43 | } 44 | 45 | } // namespace tflite 46 | 47 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_TENSOR_CTYPES_H_ 48 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/ControllerFunctions/arm_pid_reset_q15.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_pid_reset_q15.c 6 | * Description: Q15 PID Control reset function 7 | * 8 | * $Date: 18. March 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | 33 | /** 34 | @addtogroup PID 35 | @{ 36 | */ 37 | 38 | /** 39 | @brief Reset function for the Q15 PID Control. 40 | @param[in,out] S points to an instance of the Q15 PID structure 41 | @return none 42 | 43 | @par Details 44 | The function resets the state buffer to zeros. 45 | */ 46 | 47 | void arm_pid_reset_q15( 48 | arm_pid_instance_q15 * S) 49 | { 50 | /* Reset state to zero, The size will be always 3 samples */ 51 | memset(S->state, 0, 3U * sizeof(q15_t)); 52 | } 53 | 54 | /** 55 | @} end of PID group 56 | */ 57 | 58 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 59 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/ControllerFunctions/arm_pid_reset_q31.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_pid_reset_q31.c 6 | * Description: Q31 PID Control reset function 7 | * 8 | * $Date: 18. March 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | 33 | /** 34 | @addtogroup PID 35 | @{ 36 | */ 37 | 38 | /** 39 | @brief Reset function for the Q31 PID Control. 40 | @param[in,out] S points to an instance of the Q31 PID structure 41 | @return none 42 | 43 | @par Details 44 | The function resets the state buffer to zeros. 45 | */ 46 | 47 | void arm_pid_reset_q31( 48 | arm_pid_instance_q31 * S) 49 | { 50 | /* Reset state to zero, The size will be always 3 samples */ 51 | memset(S->state, 0, 3U * sizeof(q31_t)); 52 | } 53 | 54 | /** 55 | @} end of PID group 56 | */ 57 | 58 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 59 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/SupportFunctions/arm_merge_sort_init_f32.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_merge_sort_init_f32.c 6 | * Description: Floating point merge sort initialization function 7 | * 8 | * $Date: 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M and Cortex-A cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | 33 | /** 34 | @ingroup groupSupport 35 | */ 36 | 37 | /** 38 | @addtogroup Sorting 39 | @{ 40 | */ 41 | 42 | 43 | /** 44 | * @param[in,out] S points to an instance of the sorting structure. 45 | * @param[in] dir Sorting order. 46 | * @param[in] buffer Working buffer. 47 | */ 48 | void arm_merge_sort_init_f32(arm_merge_sort_instance_f32 * S, arm_sort_dir dir, float32_t * buffer) 49 | { 50 | S->dir = dir; 51 | S->buffer = buffer; 52 | } 53 | /** 54 | @} end of Sorting group 55 | */ 56 | 57 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 58 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/dsp/returntypes.hpp: -------------------------------------------------------------------------------- 1 | /* Edge Impulse inferencing library 2 | * Copyright (c) 2021 EdgeImpulse Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef _EIDSP_RETURN_TYPES_H_ 24 | #define _EIDSP_RETURN_TYPES_H_ 25 | 26 | #include 27 | 28 | namespace ei { 29 | 30 | typedef enum { 31 | EIDSP_OK = 0, 32 | EIDSP_OUT_OF_MEM = -1002, 33 | EIDSP_SIGNAL_SIZE_MISMATCH = -1003, 34 | EIDSP_MATRIX_SIZE_MISMATCH = -1004, 35 | EIDSP_DCT_ERROR = -1005, 36 | EIDSP_INPUT_MATRIX_EMPTY = -1006, 37 | EIDSP_BUFFER_SIZE_MISMATCH = -1007, 38 | EIDSP_PARAMETER_INVALID = -1008, 39 | EIDSP_UNEXPECTED_NEXT_OFFSET = -1009, 40 | EIDSP_OUT_OF_BOUNDS = -1010, 41 | EIDSP_UNSUPPORTED_FILTER_CONFIG = -1011, 42 | EIDSP_NARROWING = -1012, 43 | EIDSP_BLOCK_VERSION_INCORRECT = -1013 44 | } EIDSP_RETURN_T; 45 | 46 | } // namespace ei 47 | 48 | #endif // _EIDSP_RETURN_TYPES_H_ 49 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/ControllerFunctions/arm_pid_reset_f32.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_pid_reset_f32.c 6 | * Description: Floating-point PID Control reset function 7 | * 8 | * $Date: 18. March 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | 33 | /** 34 | @addtogroup PID 35 | @{ 36 | */ 37 | 38 | /** 39 | @brief Reset function for the floating-point PID Control. 40 | @param[in,out] S points to an instance of the floating-point PID structure 41 | @return none 42 | 43 | @par Details 44 | The function resets the state buffer to zeros. 45 | */ 46 | 47 | void arm_pid_reset_f32( 48 | arm_pid_instance_f32 * S) 49 | { 50 | /* Reset state to zero, The size will be always 3 samples */ 51 | memset(S->state, 0, 3U * sizeof(float32_t)); 52 | } 53 | 54 | /** 55 | @} end of PID group 56 | */ 57 | 58 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 59 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/SupportFunctions/arm_sort_init_f32.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_sort_init_f32.c 6 | * Description: Floating point sort initialization function 7 | * 8 | * $Date: 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M and Cortex-A cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | #include "edge-impulse-sdk/CMSIS/DSP/PrivateInclude/arm_sorting.h" 33 | 34 | /** 35 | @ingroup groupSupport 36 | */ 37 | 38 | /** 39 | @addtogroup Sorting 40 | @{ 41 | */ 42 | 43 | 44 | /** 45 | * @param[in,out] S points to an instance of the sorting structure. 46 | * @param[in] alg Selected algorithm. 47 | * @param[in] dir Sorting order. 48 | */ 49 | void arm_sort_init_f32(arm_sort_instance_f32 * S, arm_sort_alg alg, arm_sort_dir dir) 50 | { 51 | S->alg = alg; 52 | S->dir = dir; 53 | } 54 | 55 | /** 56 | @} end of Sorting group 57 | */ 58 | 59 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 60 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/NN/Include/arm_nn_tables.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS NN Library 3 | * Title: arm_nn_tables.h 4 | * Description: Extern declaration for NN tables 5 | * 6 | * $Date: 17. January 2018 7 | * $Revision: V.1.0.0 8 | * 9 | * Target Processor: Cortex-M cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2018 Arm Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #ifndef _ARM_NN_TABLES_H 30 | #define _ARM_NN_TABLES_H 31 | 32 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 33 | 34 | /** 35 | * @brief tables for various activation functions 36 | * 37 | */ 38 | 39 | extern const q15_t sigmoidTable_q15[256]; 40 | extern const q7_t sigmoidTable_q7[256]; 41 | 42 | extern const q7_t tanhTable_q7[256]; 43 | extern const q15_t tanhTable_q15[256]; 44 | 45 | /** 46 | * @brief 2-way tables for various activation functions 47 | * 48 | * 2-way table, H table for value larger than 1/4 49 | * L table for value smaller than 1/4, H table for remaining 50 | * We have this only for the q15_t version. It does not make 51 | * sense to have it for q7_t type 52 | */ 53 | extern const q15_t sigmoidHTable_q15[192]; 54 | extern const q15_t sigmoidLTable_q15[128]; 55 | 56 | #endif /* ARM_NN_TABLES_H */ 57 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/kernels/internal/reference/round.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ROUND_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ROUND_H_ 17 | 18 | #include 19 | 20 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/types.h" 21 | 22 | namespace tflite { 23 | 24 | namespace reference_ops { 25 | 26 | inline float RoundToNearest(float value) { 27 | auto floor_val = std::floor(value); 28 | auto diff = value - floor_val; 29 | if ((diff < 0.5f) || 30 | ((diff == 0.5f) && (static_cast(floor_val) % 2 == 0))) { 31 | return floor_val; 32 | } else { 33 | return floor_val = floor_val + 1.0f; 34 | } 35 | } 36 | 37 | inline void Round(const RuntimeShape& input_shape, const float* input_data, 38 | const RuntimeShape& output_shape, float* output_data) { 39 | const int flat_size = MatchingFlatSize(input_shape, output_shape); 40 | for (int i = 0; i < flat_size; ++i) { 41 | // Note that this implementation matches that of tensorFlow tf.round 42 | // and corresponds to the bankers rounding method. 43 | // cfenv (for fesetround) is not yet supported universally on Android, so 44 | // using a work around. 45 | output_data[i] = RoundToNearest(input_data[i]); 46 | } 47 | } 48 | 49 | } // namespace reference_ops 50 | } // namespace tflite 51 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_ROUND_H_ 52 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/memory_helpers.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_MICRO_MEMORY_HELPERS_H_ 16 | #define TENSORFLOW_LITE_MICRO_MEMORY_HELPERS_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "edge-impulse-sdk/tensorflow/lite/c/common.h" 22 | #include "edge-impulse-sdk/tensorflow/lite/core/api/error_reporter.h" 23 | #include "edge-impulse-sdk/tensorflow/lite/schema/schema_generated.h" 24 | 25 | namespace tflite { 26 | 27 | // Returns the next pointer address aligned to the given alignment. 28 | uint8_t* AlignPointerUp(uint8_t* data, size_t alignment); 29 | 30 | // Returns the previous pointer address aligned to the given alignment. 31 | uint8_t* AlignPointerDown(uint8_t* data, size_t alignment); 32 | 33 | // Returns an increased size that's a multiple of alignment. 34 | size_t AlignSizeUp(size_t size, size_t alignment); 35 | 36 | // Returns size in bytes for a given TfLiteType. 37 | TfLiteStatus TfLiteTypeSizeOf(TfLiteType type, size_t* size, 38 | ErrorReporter* reporter); 39 | 40 | // How many bytes are needed to hold a tensor's contents. 41 | TfLiteStatus BytesRequiredForTensor(const tflite::Tensor& flatbuffer_tensor, 42 | size_t* bytes, size_t* type_size, 43 | ErrorReporter* error_reporter); 44 | 45 | } // namespace tflite 46 | 47 | #endif // TENSORFLOW_LITE_MICRO_MEMORY_HELPERS_H_ 48 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/memory_planner/linear_memory_planner.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_LINEAR_MEMORY_PLANNER_H_ 17 | #define TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_LINEAR_MEMORY_PLANNER_H_ 18 | 19 | #include "edge-impulse-sdk/tensorflow/lite/micro/compatibility.h" 20 | #include "edge-impulse-sdk/tensorflow/lite/micro/memory_planner/memory_planner.h" 21 | 22 | namespace tflite { 23 | 24 | // The simplest possible memory planner that just lays out all buffers at 25 | // increasing offsets without trying to reuse memory. 26 | class LinearMemoryPlanner : public MemoryPlanner { 27 | public: 28 | LinearMemoryPlanner(); 29 | ~LinearMemoryPlanner() override; 30 | 31 | TfLiteStatus AddBuffer(tflite::ErrorReporter* error_reporter, int size, 32 | int first_time_used, int last_time_used) override; 33 | 34 | size_t GetMaximumMemorySize() override; 35 | int GetBufferCount() override; 36 | TfLiteStatus GetOffsetForBuffer(tflite::ErrorReporter* error_reporter, 37 | int buffer_index, int* offset) override; 38 | 39 | private: 40 | static constexpr int kMaxBufferCount = 1024; 41 | size_t buffer_offsets_[kMaxBufferCount]; 42 | int current_buffer_count_; 43 | size_t next_free_offset_; 44 | 45 | TF_LITE_REMOVE_VIRTUAL_DELETE 46 | }; 47 | 48 | } // namespace tflite 49 | 50 | #endif // TENSORFLOW_LITE_MICRO_MEMORY_PLANNER_LINEAR_MEMORY_PLANNER_H_ 51 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/StatisticsFunctions/arm_entropy_f64.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_logsumexp_f64.c 6 | * Description: LogSumExp 7 | * 8 | * 9 | * Target Processor: Cortex-M and Cortex-A cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2020 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 30 | #include 31 | #include 32 | 33 | /** 34 | * @addtogroup groupStats 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @brief Entropy 40 | * 41 | * @param[in] pSrcA Array of input values. 42 | * @param[in] blockSize Number of samples in the input array. 43 | * @return Entropy -Sum(p ln p) 44 | * 45 | */ 46 | 47 | float64_t arm_entropy_f64(const float64_t * pSrcA, uint32_t blockSize) 48 | { 49 | const float64_t *pIn; 50 | uint32_t blkCnt; 51 | float64_t accum, p; 52 | 53 | pIn = pSrcA; 54 | blkCnt = blockSize; 55 | 56 | accum = 0.0f; 57 | 58 | while(blkCnt > 0) 59 | { 60 | p = *pIn++; 61 | 62 | accum += p * log(p); 63 | 64 | blkCnt--; 65 | 66 | } 67 | 68 | return(-accum); 69 | } 70 | 71 | /** 72 | * @} end of groupStats group 73 | */ 74 | 75 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 76 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/kernels/mli_slicers.h: -------------------------------------------------------------------------------- 1 | // Patched by Edge Impulse to include reference, CMSIS-NN and ARC kernels 2 | #include "../../../../classifier/ei_classifier_config.h" 3 | #if EI_CLASSIFIER_TFLITE_ENABLE_ARC == 1 4 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | ==============================================================================*/ 18 | 19 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_ARC_MLI_SLICERS_H_ 20 | #define TENSORFLOW_LITE_MICRO_KERNELS_ARC_MLI_SLICERS_H_ 21 | 22 | #include "mli_api.h" // NOLINT 23 | namespace tflite { 24 | namespace ops { 25 | namespace micro { 26 | 27 | class TensorSlicer { 28 | public: 29 | TensorSlicer(const mli_tensor* full_tensor, int slice_dim, int slice_size, 30 | int padding_pre = 0, int padding_post = 0, int overlap = 0, 31 | bool interleave_mode = false); 32 | ~TensorSlicer() = default; 33 | 34 | void Next(); 35 | bool Done(); 36 | int GetPaddingPre(); 37 | int GetPaddingPost(); 38 | 39 | mli_tensor* Sub(); 40 | 41 | // Default constructor is deleted 42 | TensorSlicer() = delete; 43 | 44 | private: 45 | const mli_tensor* full_tensor_; 46 | mli_tensor sub_tensor_; 47 | mli_sub_tensor_cfg sub_cfg_; 48 | bool done_; 49 | int sliceDim_; 50 | int pad_pre_, pad_post_, overlap_; 51 | int actual_padding_pre, actual_padding_post; 52 | 53 | void ComputeSubTensor(); 54 | }; 55 | 56 | } // namespace micro 57 | } // namespace ops 58 | } // namespace tflite 59 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_ARC_MLI_SLICERS_H_ 60 | 61 | #endif // EI_CLASSIFIER_TFLITE_ENABLE_ARC == 1 62 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_cosine_distance_f32.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | 4 | /* ---------------------------------------------------------------------- 5 | * Project: CMSIS DSP Library 6 | * Title: arm_cosine_distance_f32.c 7 | * Description: Cosine distance between two vectors 8 | * 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 31 | #include 32 | #include 33 | 34 | 35 | /** 36 | @addtogroup FloatDist 37 | @{ 38 | */ 39 | 40 | 41 | 42 | /** 43 | * @brief Cosine distance between two vectors 44 | * 45 | * @param[in] pA First vector 46 | * @param[in] pB Second vector 47 | * @param[in] blockSize vector length 48 | * @return distance 49 | * 50 | */ 51 | 52 | float32_t arm_cosine_distance_f32(const float32_t *pA,const float32_t *pB, uint32_t blockSize) 53 | { 54 | float32_t pwra,pwrb,dot,tmp; 55 | 56 | arm_power_f32(pA, blockSize, &pwra); 57 | arm_power_f32(pB, blockSize, &pwrb); 58 | 59 | arm_dot_prod_f32(pA,pB,blockSize,&dot); 60 | 61 | arm_sqrt_f32(pwra * pwrb, &tmp); 62 | return(1.0f - dot / tmp); 63 | 64 | } 65 | 66 | 67 | 68 | /** 69 | * @} end of FloatDist group 70 | */ 71 | 72 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 73 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/NN/Source/ConcatenationFunctions/arm_concatenation_s8_w.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2019 Arm Limited or its affiliates. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /* ---------------------------------------------------------------------- 20 | * Project: CMSIS NN Library 21 | * Title: arm_concatenation_s8_w.c 22 | * Description: s8 version of concatenation along the W axis 23 | * 24 | * $Date: October 2019 25 | * $Revision: V.1.0.0 26 | * 27 | * Target Processor: Cortex-M cores 28 | * 29 | * -------------------------------------------------------------------- */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/NN/Include/arm_nnfunctions.h" 32 | 33 | /** 34 | * @ingroup groupNN 35 | */ 36 | 37 | /** 38 | * @addtogroup Concatenation 39 | * @{ 40 | */ 41 | 42 | /* 43 | * s8 version of concatenation along the W axis 44 | * 45 | * Refer to header file for details. 46 | * 47 | */ 48 | void arm_concatenation_s8_w(const int8_t *input, 49 | const uint16_t input_x, 50 | const uint16_t input_y, 51 | const uint16_t input_z, 52 | const uint16_t input_w, 53 | int8_t *output, 54 | const uint32_t offset_w) 55 | { 56 | const uint32_t input_copy_size = input_x * input_y * input_z * input_w; 57 | 58 | output += offset_w * (input_x * input_y * input_z); 59 | 60 | memcpy(output, input, input_copy_size); 61 | } 62 | 63 | /** 64 | * @} end of Concatenation group 65 | */ 66 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/classifier/ei_classifier_types.h: -------------------------------------------------------------------------------- 1 | /* Edge Impulse inferencing library 2 | * Copyright (c) 2021 EdgeImpulse Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | #ifndef _EDGE_IMPULSE_RUN_CLASSIFIER_TYPES_H_ 24 | #define _EDGE_IMPULSE_RUN_CLASSIFIER_TYPES_H_ 25 | 26 | #include 27 | #include "model-parameters/model_metadata.h" 28 | 29 | typedef struct { 30 | const char *label; 31 | float value; 32 | } ei_impulse_result_classification_t; 33 | 34 | typedef struct { 35 | int sampling; 36 | int dsp; 37 | int classification; 38 | int anomaly; 39 | } ei_impulse_result_timing_t; 40 | 41 | typedef struct { 42 | ei_impulse_result_classification_t classification[EI_CLASSIFIER_LABEL_COUNT]; 43 | float anomaly; 44 | ei_impulse_result_timing_t timing; 45 | } ei_impulse_result_t; 46 | 47 | typedef struct { 48 | uint32_t buf_idx; 49 | float running_sum; 50 | #if (EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW > 1) 51 | float maf_buffer[(EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW >> 1)]; 52 | #else 53 | float maf_buffer[1]; 54 | #endif 55 | }ei_impulse_maf; 56 | 57 | #endif // _EDGE_IMPULSE_RUN_CLASSIFIER_TYPES_H_ 58 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/micro_time.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // Reference implementation of timer functions. Platforms are not required to 17 | // implement these timer methods, but they are required to enable profiling. 18 | 19 | // On platforms that have a POSIX stack or C library, it can be written using 20 | // methods from or clock() from . 21 | 22 | // To add an equivalent function for your own platform, create your own 23 | // implementation file, and place it in a subfolder with named after the OS 24 | // you're targeting. For example, see the Cortex M bare metal version in 25 | // tensorflow/lite/micro/bluepill/micro_time.cc or the mbed one on 26 | // tensorflow/lite/micro/mbed/micro_time.cc. 27 | 28 | #include "edge-impulse-sdk/tensorflow/lite/micro/micro_time.h" 29 | 30 | namespace tflite { 31 | 32 | // Reference implementation of the ticks_per_second() function that's required 33 | // for a platform to support Tensorflow Lite for Microcontrollers profiling. 34 | // This returns 0 by default because timing is an optional feature that builds 35 | // without errors on platforms that do not need it. 36 | int32_t ticks_per_second() { return 0; } 37 | 38 | // Reference implementation of the GetCurrentTimeTicks() function that's 39 | // required for a platform to support Tensorflow Lite for Microcontrollers 40 | // profiling. This returns 0 by default because timing is an optional feature 41 | // that builds without errors on platforms that do not need it. 42 | int32_t GetCurrentTimeTicks() { return 0; } 43 | 44 | } // namespace tflite 45 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/MatrixFunctions/arm_mat_init_q15.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_mat_init_q15.c 6 | * Description: Q15 matrix initialization 7 | * 8 | * $Date: 18. March 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | 33 | /** 34 | @ingroup groupMatrix 35 | */ 36 | 37 | /** 38 | @addtogroup MatrixInit 39 | @{ 40 | */ 41 | 42 | /** 43 | @brief Q15 matrix initialization. 44 | @param[in,out] S points to an instance of the floating-point matrix structure 45 | @param[in] nRows number of rows in the matrix 46 | @param[in] nColumns number of columns in the matrix 47 | @param[in] pData points to the matrix data array 48 | @return none 49 | */ 50 | 51 | void arm_mat_init_q15( 52 | arm_matrix_instance_q15 * S, 53 | uint16_t nRows, 54 | uint16_t nColumns, 55 | q15_t * pData) 56 | { 57 | /* Assign Number of Rows */ 58 | S->numRows = nRows; 59 | 60 | /* Assign Number of Columns */ 61 | S->numCols = nColumns; 62 | 63 | /* Assign Data pointer */ 64 | S->pData = pData; 65 | } 66 | 67 | /** 68 | @} end of MatrixInit group 69 | */ 70 | 71 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 72 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Include/arm_const_structs_f16.h: -------------------------------------------------------------------------------- 1 | /* ---------------------------------------------------------------------- 2 | * Project: CMSIS DSP Library 3 | * Title: arm_const_structs_f16.h 4 | * Description: Constant structs that are initialized for user convenience. 5 | * For example, some can be given as arguments to the arm_cfft_f16() function. 6 | * 7 | * $Date: 20. April 2020 8 | * $Revision: V.1.5.1 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2020 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #ifndef _ARM_CONST_STRUCTS_F16_H 31 | #define _ARM_CONST_STRUCTS_F16_H 32 | 33 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math_f16.h" 34 | #include "arm_common_tables_f16.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C" 38 | { 39 | #endif 40 | 41 | #if !defined(__CC_ARM) && defined(ARM_FLOAT16_SUPPORTED) 42 | extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len16; 43 | extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len32; 44 | extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len64; 45 | extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len128; 46 | extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len256; 47 | extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len512; 48 | extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len1024; 49 | extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len2048; 50 | extern const arm_cfft_instance_f16 arm_cfft_sR_f16_len4096; 51 | #endif 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/kernels/activation_utils.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_KERNELS_ACTIVATION_UTILS_H_ 17 | #define TENSORFLOW_LITE_MICRO_KERNELS_ACTIVATION_UTILS_H_ 18 | 19 | #include 20 | #include 21 | 22 | #include "edge-impulse-sdk/tensorflow/lite/c/builtin_op_data.h" 23 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/cppmath.h" 24 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/max.h" 25 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/min.h" 26 | 27 | namespace tflite { 28 | namespace ops { 29 | namespace micro { 30 | 31 | // Returns the floating point value for a fused activation: 32 | inline float ActivationValFloat(TfLiteFusedActivation act, float a) { 33 | switch (act) { 34 | case kTfLiteActNone: 35 | return a; 36 | case kTfLiteActRelu: 37 | return TfLiteMax(0.0f, a); 38 | case kTfLiteActReluN1To1: 39 | return TfLiteMax(-1.0f, TfLiteMin(a, 1.0f)); 40 | case kTfLiteActRelu6: 41 | return TfLiteMax(0.0f, TfLiteMin(a, 6.0f)); 42 | case kTfLiteActTanh: 43 | return std::tanh(a); 44 | case kTfLiteActSignBit: 45 | return std::signbit(a); 46 | case kTfLiteActSigmoid: 47 | return 1.0f / (1.0f + std::exp(-a)); 48 | } 49 | return 0.0f; // To indicate an unsupported activation (i.e. when a new fused 50 | // activation is added to the enum and not handled here). 51 | } 52 | 53 | } // namespace micro 54 | } // namespace ops 55 | } // namespace tflite 56 | 57 | #endif // TENSORFLOW_LITE_MICRO_KERNELS_ACTIVATION_UTILS_H_ 58 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_hamming_distance.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | 4 | /* ---------------------------------------------------------------------- 5 | * Project: CMSIS DSP Library 6 | * Title: arm_hamming_distance.c 7 | * Description: Hamming distance between two vectors 8 | * 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 31 | #include 32 | #include 33 | 34 | 35 | extern void arm_boolean_distance_TF_FT(const uint32_t *pA 36 | , const uint32_t *pB 37 | , uint32_t numberOfBools 38 | , uint32_t *cTF 39 | , uint32_t *cFT 40 | ); 41 | 42 | /** 43 | @addtogroup BoolDist 44 | @{ 45 | */ 46 | 47 | 48 | /** 49 | * @brief Hamming distance between two vectors 50 | * 51 | * @param[in] pA First vector of packed booleans 52 | * @param[in] pB Second vector of packed booleans 53 | * @param[in] numberOfBools Number of booleans 54 | * @return distance 55 | * 56 | */ 57 | 58 | float32_t arm_hamming_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools) 59 | { 60 | uint32_t ctf=0,cft=0; 61 | 62 | arm_boolean_distance_TF_FT(pA, pB, numberOfBools, &ctf, &cft); 63 | 64 | return(1.0*(ctf + cft) / numberOfBools); 65 | } 66 | 67 | 68 | /** 69 | * @} end of BoolDist group 70 | */ 71 | 72 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 73 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/memory_planner/linear_memory_planner.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "edge-impulse-sdk/tensorflow/lite/micro/memory_planner/linear_memory_planner.h" 17 | 18 | namespace tflite { 19 | 20 | LinearMemoryPlanner::LinearMemoryPlanner() 21 | : current_buffer_count_(0), next_free_offset_(0) {} 22 | LinearMemoryPlanner::~LinearMemoryPlanner() {} 23 | 24 | TfLiteStatus LinearMemoryPlanner::AddBuffer( 25 | tflite::ErrorReporter* error_reporter, int size, int first_time_used, 26 | int last_time_used) { 27 | if (current_buffer_count_ >= kMaxBufferCount) { 28 | TF_LITE_REPORT_ERROR(error_reporter, "Too many buffers (max is %d)", 29 | kMaxBufferCount); 30 | return kTfLiteError; 31 | } 32 | buffer_offsets_[current_buffer_count_] = next_free_offset_; 33 | next_free_offset_ += size; 34 | ++current_buffer_count_; 35 | return kTfLiteOk; 36 | } 37 | 38 | size_t LinearMemoryPlanner::GetMaximumMemorySize() { return next_free_offset_; } 39 | 40 | int LinearMemoryPlanner::GetBufferCount() { return current_buffer_count_; } 41 | 42 | TfLiteStatus LinearMemoryPlanner::GetOffsetForBuffer( 43 | tflite::ErrorReporter* error_reporter, int buffer_index, int* offset) { 44 | if ((buffer_index < 0) || (buffer_index >= current_buffer_count_)) { 45 | TF_LITE_REPORT_ERROR(error_reporter, 46 | "buffer index %d is outside range 0 to %d", 47 | buffer_index, current_buffer_count_); 48 | return kTfLiteError; 49 | } 50 | *offset = buffer_offsets_[buffer_index]; 51 | return kTfLiteOk; 52 | } 53 | 54 | } // namespace tflite 55 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/PrivateInclude/arm_vec_fft.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file arm_vec_fft.h 3 | * @brief Private header file for CMSIS DSP Library 4 | * @version V1.7.0 5 | * @date 07. January 2020 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2010-2020 Arm Limited or its affiliates. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #ifndef _ARM_VEC_FFT_H_ 26 | #define _ARM_VEC_FFT_H_ 27 | 28 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 29 | #include "arm_helium_utils.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" 33 | { 34 | #endif 35 | 36 | #if (defined(ARM_MATH_MVEF) || defined(ARM_MATH_MVEI) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE) 37 | 38 | #define MVE_CMPLX_ADD_A_ixB(A, B) vcaddq_rot90(A,B) 39 | #define MVE_CMPLX_SUB_A_ixB(A,B) vcaddq_rot270(A,B) 40 | #define MVE_CMPLX_MULT_FLT_AxB(A,B) vcmlaq_rot90(vcmulq(A, B), A, B) 41 | #define MVE_CMPLX_MULT_FLT_Conj_AxB(A,B) vcmlaq_rot270(vcmulq(A, B), A, B) 42 | 43 | #define MVE_CMPLX_MULT_FX_AxB(A,B) vqdmladhxq(vqdmlsdhq((__typeof(A))vuninitializedq_s32(), A, B), A, B); 44 | #define MVE_CMPLX_MULT_FX_AxConjB(A,B) vqdmladhq(vqdmlsdhxq((__typeof(A))vuninitializedq_s32(), A, B), A, B); 45 | 46 | #define MVE_CMPLX_ADD_FX_A_ixB(A, B) vhcaddq_rot90(A,B) 47 | #define MVE_CMPLX_SUB_FX_A_ixB(A,B) vhcaddq_rot270(A,B) 48 | 49 | 50 | #endif /* (defined(ARM_MATH_MVEF) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE)*/ 51 | 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif 56 | 57 | 58 | #endif /* _ARM_VEC_FFT_H_ */ 59 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_russellrao_distance.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | 4 | /* ---------------------------------------------------------------------- 5 | * Project: CMSIS DSP Library 6 | * Title: arm_russellrao_distance.c 7 | * Description: Russell-Rao distance between two vectors 8 | * 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 31 | #include 32 | #include 33 | 34 | 35 | 36 | extern void arm_boolean_distance_TT(const uint32_t *pA 37 | , const uint32_t *pB 38 | , uint32_t numberOfBools 39 | , uint32_t *cTT 40 | ); 41 | 42 | 43 | /** 44 | @addtogroup BoolDist 45 | @{ 46 | */ 47 | 48 | /** 49 | * @brief Russell-Rao distance between two vectors 50 | * 51 | * @param[in] pA First vector of packed booleans 52 | * @param[in] pB Second vector of packed booleans 53 | * @param[in] numberOfBools Number of booleans 54 | * @return distance 55 | * 56 | */ 57 | 58 | float32_t arm_russellrao_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools) 59 | { 60 | uint32_t ctt=0; 61 | 62 | 63 | arm_boolean_distance_TT(pA, pB, numberOfBools, &ctt); 64 | 65 | 66 | return(1.0*(numberOfBools - ctt) / ((float32_t)numberOfBools)); 67 | } 68 | 69 | 70 | /** 71 | * @} end of BoolDist group 72 | */ 73 | 74 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 75 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/MatrixFunctions/arm_mat_init_q31.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_mat_init_q31.c 6 | * Description: Q31 matrix initialization 7 | * 8 | * $Date: 18. March 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | 33 | /** 34 | @ingroup groupMatrix 35 | */ 36 | 37 | /** 38 | @defgroup MatrixInit Matrix Initialization 39 | 40 | */ 41 | 42 | /** 43 | @addtogroup MatrixInit 44 | @{ 45 | */ 46 | 47 | /** 48 | @brief Q31 matrix initialization. 49 | @param[in,out] S points to an instance of the Q31 matrix structure 50 | @param[in] nRows number of rows in the matrix 51 | @param[in] nColumns number of columns in the matrix 52 | @param[in] pData points to the matrix data array 53 | @return none 54 | */ 55 | 56 | void arm_mat_init_q31( 57 | arm_matrix_instance_q31 * S, 58 | uint16_t nRows, 59 | uint16_t nColumns, 60 | q31_t * pData) 61 | { 62 | /* Assign Number of Rows */ 63 | S->numRows = nRows; 64 | 65 | /* Assign Number of Columns */ 66 | S->numCols = nColumns; 67 | 68 | /* Assign Data pointer */ 69 | S->pData = pData; 70 | } 71 | 72 | /** 73 | @} end of MatrixInit group 74 | */ 75 | 76 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 77 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/StatisticsFunctions/arm_logsumexp_dot_prod_f32.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_logsumexp_f32.c 6 | * Description: LogSumExp 7 | * 8 | * 9 | * Target Processor: Cortex-M and Cortex-A cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 30 | #include 31 | #include 32 | 33 | 34 | /** 35 | * @addtogroup groupStats 36 | * @{ 37 | */ 38 | 39 | 40 | /** 41 | * @brief Dot product with log arithmetic 42 | * 43 | * Vectors are containing the log of the samples 44 | * 45 | * @param[in] *pSrcA points to the first input vector 46 | * @param[in] *pSrcB points to the second input vector 47 | * @param[in] blockSize number of samples in each vector 48 | * @param[in] *pTmpBuffer temporary buffer of length blockSize 49 | * @return The log of the dot product. 50 | * 51 | */ 52 | 53 | 54 | float32_t arm_logsumexp_dot_prod_f32(const float32_t * pSrcA, 55 | const float32_t * pSrcB, 56 | uint32_t blockSize, 57 | float32_t *pTmpBuffer) 58 | { 59 | float32_t result; 60 | arm_add_f32((float32_t*)pSrcA, (float32_t*)pSrcB, pTmpBuffer, blockSize); 61 | 62 | result = arm_logsumexp_f32(pTmpBuffer, blockSize); 63 | return(result); 64 | } 65 | 66 | /** 67 | * @} end of groupStats group 68 | */ 69 | 70 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 71 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/kernels/floor.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/reference/floor.h" 17 | 18 | #include "edge-impulse-sdk/tensorflow/lite/c/common.h" 19 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/tensor_ctypes.h" 20 | #include "edge-impulse-sdk/tensorflow/lite/kernels/kernel_util.h" 21 | 22 | namespace tflite { 23 | namespace ops { 24 | namespace micro { 25 | namespace floor { 26 | 27 | constexpr int kInputTensor = 0; 28 | constexpr int kOutputTensor = 0; 29 | 30 | TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { 31 | const TfLiteTensor* input = GetInput(context, node, kInputTensor); 32 | TF_LITE_ENSURE_TYPES_EQ(context, input->type, kTfLiteFloat32); 33 | TfLiteTensor* output = GetOutput(context, node, kOutputTensor); 34 | reference_ops::Floor(GetTensorShape(input), GetTensorData(input), 35 | GetTensorShape(output), GetTensorData(output)); 36 | return kTfLiteOk; 37 | } 38 | } // namespace floor 39 | 40 | TfLiteRegistration* Register_FLOOR() { 41 | static TfLiteRegistration r = {/*init=*/nullptr, 42 | /*free=*/nullptr, 43 | /*prepare=*/nullptr, 44 | /*invoke=*/floor::Eval, 45 | /*profiling_string=*/nullptr, 46 | /*builtin_code=*/0, 47 | /*custom_name=*/nullptr, 48 | /*version=*/0}; 49 | return &r; 50 | } 51 | 52 | } // namespace micro 53 | } // namespace ops 54 | } // namespace tflite 55 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_jaccard_distance.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | 4 | /* ---------------------------------------------------------------------- 5 | * Project: CMSIS DSP Library 6 | * Title: arm_jaccard_distance.c 7 | * Description: Jaccard distance between two vectors 8 | * 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 31 | #include 32 | #include 33 | 34 | 35 | 36 | extern void arm_boolean_distance_TT_TF_FT(const uint32_t *pA 37 | , const uint32_t *pB 38 | , uint32_t numberOfBools 39 | , uint32_t *cTT 40 | , uint32_t *cTF 41 | , uint32_t *cFT 42 | ); 43 | 44 | 45 | /** 46 | @addtogroup BoolDist 47 | @{ 48 | */ 49 | 50 | /** 51 | * @brief Jaccard distance between two vectors 52 | * 53 | * @param[in] pA First vector of packed booleans 54 | * @param[in] pB Second vector of packed booleans 55 | * @param[in] numberOfBools Number of booleans 56 | * @return distance 57 | * 58 | */ 59 | 60 | float32_t arm_jaccard_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools) 61 | { 62 | uint32_t ctt=0,ctf=0,cft=0; 63 | 64 | arm_boolean_distance_TT_TF_FT(pA, pB, numberOfBools, &ctt, &ctf, &cft); 65 | 66 | return(1.0*(ctf + cft) / (ctt + cft + ctf)); 67 | } 68 | 69 | 70 | /** 71 | * @} end of BoolDist group 72 | */ 73 | 74 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 75 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_boolean_distance.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | 4 | /* ---------------------------------------------------------------------- 5 | * Project: CMSIS DSP Library 6 | * Title: arm_svm_linear_init_f32.c 7 | * Description: SVM Linear Instance Initialization 8 | * 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 31 | #include 32 | #include 33 | 34 | 35 | 36 | 37 | #if defined(ARM_MATH_NEON) 38 | 39 | #include "NEMath.h" 40 | 41 | #endif 42 | 43 | 44 | #define TT 45 | #define TF 46 | #define FT 47 | #define EXT _TT_TF_FT 48 | #include "edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_boolean_distance_template.h" 49 | 50 | #undef TT 51 | #undef FF 52 | #undef TF 53 | #undef FT 54 | #undef EXT 55 | #define TF 56 | #define FT 57 | #define EXT _TF_FT 58 | #include "edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_boolean_distance_template.h" 59 | 60 | #undef TT 61 | #undef FF 62 | #undef TF 63 | #undef FT 64 | #undef EXT 65 | #define TT 66 | #define FF 67 | #define TF 68 | #define FT 69 | #define EXT _TT_FF_TF_FT 70 | #include "edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_boolean_distance_template.h" 71 | 72 | #undef TT 73 | #undef FF 74 | #undef TF 75 | #undef FT 76 | #undef EXT 77 | #define TT 78 | #define EXT _TT 79 | #include "edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_boolean_distance_template.h" 80 | 81 | 82 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 83 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/NN/Source/ConcatenationFunctions/arm_concatenation_s8_x.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2019 Arm Limited or its affiliates. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /* ---------------------------------------------------------------------- 20 | * Project: CMSIS NN Library 21 | * Title: arm_concatenation_s8_x.c 22 | * Description: s8 version of concatenation along the X axis 23 | * 24 | * $Date: October 2019 25 | * $Revision: V.1.0.0 26 | * 27 | * Target Processor: Cortex-M cores 28 | * 29 | * -------------------------------------------------------------------- */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/NN/Include/arm_nnfunctions.h" 32 | 33 | /** 34 | * @ingroup groupNN 35 | */ 36 | 37 | /** 38 | * @addtogroup Concatenation 39 | * @{ 40 | */ 41 | 42 | /* 43 | * s8 version of concatenation along the X axis 44 | * 45 | * Refer to header file for details. 46 | * 47 | */ 48 | void arm_concatenation_s8_x(const int8_t *input, 49 | const uint16_t input_x, 50 | const uint16_t input_y, 51 | const uint16_t input_z, 52 | const uint16_t input_w, 53 | int8_t *output, 54 | const uint16_t output_x, 55 | const uint32_t offset_x) 56 | { 57 | const uint32_t num_iterations = input_y * input_z * input_w; 58 | 59 | output += offset_x; 60 | 61 | uint32_t i; 62 | 63 | // Copy per row 64 | for (i = 0; i < num_iterations; ++i) 65 | { 66 | memcpy(output, input, input_x); 67 | input += input_x; 68 | output += output_x; 69 | } 70 | } 71 | 72 | /** 73 | * @} end of Concatenation group 74 | */ 75 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/core/api/op_resolver.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_ 16 | #define TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_ 17 | 18 | #include "edge-impulse-sdk/tensorflow/lite/c/common.h" 19 | #include "edge-impulse-sdk/tensorflow/lite/core/api/error_reporter.h" 20 | #include "edge-impulse-sdk/tensorflow/lite/schema/schema_generated.h" 21 | 22 | namespace tflite { 23 | 24 | /// Abstract interface that returns TfLiteRegistrations given op codes or custom 25 | /// op names. This is the mechanism that ops being referenced in the flatbuffer 26 | /// model are mapped to executable function pointers (TfLiteRegistrations). 27 | class OpResolver { 28 | public: 29 | /// Finds the op registration for a builtin operator by enum code. 30 | virtual const TfLiteRegistration* FindOp(tflite::BuiltinOperator op, 31 | int version) const = 0; 32 | /// Finds the op registration of a custom operator by op name. 33 | virtual const TfLiteRegistration* FindOp(const char* op, 34 | int version) const = 0; 35 | virtual ~OpResolver() {} 36 | }; 37 | 38 | // Handles the logic for converting between an OperatorCode structure extracted 39 | // from a flatbuffer and information about a registered operator 40 | // implementation. 41 | TfLiteStatus GetRegistrationFromOpCode(const OperatorCode* opcode, 42 | const OpResolver& op_resolver, 43 | ErrorReporter* error_reporter, 44 | const TfLiteRegistration** registration); 45 | 46 | } // namespace tflite 47 | 48 | #endif // TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_ 49 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_kulsinski_distance.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | 4 | /* ---------------------------------------------------------------------- 5 | * Project: CMSIS DSP Library 6 | * Title: arm_kulsinski_distance.c 7 | * Description: Kulsinski distance between two vectors 8 | * 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 31 | #include 32 | #include 33 | 34 | 35 | 36 | extern void arm_boolean_distance_TT_TF_FT(const uint32_t *pA 37 | , const uint32_t *pB 38 | , uint32_t numberOfBools 39 | , uint32_t *cTT 40 | , uint32_t *cTF 41 | , uint32_t *cFT 42 | ); 43 | 44 | 45 | /** 46 | @addtogroup BoolDist 47 | @{ 48 | */ 49 | 50 | 51 | /** 52 | * @brief Kulsinski distance between two vectors 53 | * 54 | * @param[in] pA First vector of packed booleans 55 | * @param[in] pB Second vector of packed booleans 56 | * @param[in] numberOfBools Number of booleans 57 | * @return distance 58 | * 59 | */ 60 | 61 | float32_t arm_kulsinski_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools) 62 | { 63 | uint32_t ctt=0,ctf=0,cft=0; 64 | 65 | arm_boolean_distance_TT_TF_FT(pA, pB, numberOfBools, &ctt, &ctf, &cft); 66 | 67 | return(1.0*(ctf + cft - ctt + numberOfBools) / (cft + ctf + numberOfBools)); 68 | } 69 | 70 | 71 | /** 72 | * @} end of BoolDist group 73 | */ 74 | 75 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 76 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_sokalsneath_distance.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | 4 | /* ---------------------------------------------------------------------- 5 | * Project: CMSIS DSP Library 6 | * Title: arm_sokalsneath_distance.c 7 | * Description: Sokal-Sneath distance between two vectors 8 | * 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 31 | #include 32 | #include 33 | 34 | 35 | extern void arm_boolean_distance_TT_TF_FT(const uint32_t *pA 36 | , const uint32_t *pB 37 | , uint32_t numberOfBools 38 | , uint32_t *cTT 39 | , uint32_t *cTF 40 | , uint32_t *cFT 41 | ); 42 | 43 | 44 | /** 45 | @addtogroup BoolDist 46 | @{ 47 | */ 48 | 49 | /** 50 | * @brief Sokal-Sneath distance between two vectors 51 | * 52 | * @param[in] pA First vector of packed booleans 53 | * @param[in] pB Second vector of packed booleans 54 | * @param[in] numberOfBools Number of booleans 55 | * @return distance 56 | * 57 | */ 58 | 59 | float32_t arm_sokalsneath_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools) 60 | { 61 | uint32_t ctt=0,cft=0,ctf=0; 62 | float32_t r; 63 | 64 | arm_boolean_distance_TT_TF_FT(pA, pB, numberOfBools, &ctt, &ctf, &cft); 65 | 66 | r = 2.0*(ctf + cft); 67 | 68 | return(r / (r + ctt)); 69 | } 70 | 71 | 72 | /** 73 | * @} end of BoolDist group 74 | */ 75 | 76 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 77 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_yule_distance.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | 4 | /* ---------------------------------------------------------------------- 5 | * Project: CMSIS DSP Library 6 | * Title: arm_yule_distance.c 7 | * Description: Yule distance between two vectors 8 | * 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 31 | #include 32 | #include 33 | 34 | 35 | extern void arm_boolean_distance_TT_FF_TF_FT(const uint32_t *pA 36 | , const uint32_t *pB 37 | , uint32_t numberOfBools 38 | , uint32_t *cTT 39 | , uint32_t *cFF 40 | , uint32_t *cTF 41 | , uint32_t *cFT 42 | ); 43 | 44 | /** 45 | @addtogroup BoolDist 46 | @{ 47 | */ 48 | 49 | 50 | /** 51 | * @brief Yule distance between two vectors 52 | * 53 | * @param[in] pA First vector of packed booleans 54 | * @param[in] pB Second vector of packed booleans 55 | * @param[in] numberOfBools Number of booleans 56 | * @return distance 57 | * 58 | */ 59 | 60 | float32_t arm_yule_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools) 61 | { 62 | uint32_t ctt=0,cff=0,ctf=0,cft=0,r; 63 | 64 | arm_boolean_distance_TT_FF_TF_FT(pA, pB, numberOfBools, &ctt,&cff, &ctf, &cft); 65 | 66 | r = 2*(ctf * cft); 67 | 68 | return(1.0*r / (r/2.0 + ctt * cff)); 69 | } 70 | 71 | 72 | /** 73 | * @} end of BoolDist group 74 | */ 75 | 76 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 77 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/StatisticsFunctions/arm_kullback_leibler_f64.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_logsumexp_f64.c 6 | * Description: LogSumExp 7 | * 8 | * 9 | * Target Processor: Cortex-M and Cortex-A cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2020 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 30 | #include 31 | #include 32 | 33 | /** 34 | * @addtogroup groupStats 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @brief Kullback-Leibler 40 | * 41 | * @param[in] *pSrcA points to an array of input values for probaility distribution A. 42 | * @param[in] *pSrcB points to an array of input values for probaility distribution B. 43 | * @param[in] blockSize number of samples in the input array. 44 | * @return Kullback-Leibler divergence D(A || B) 45 | * 46 | */ 47 | 48 | float64_t arm_kullback_leibler_f64(const float64_t * pSrcA, const float64_t * pSrcB, uint32_t blockSize) 49 | { 50 | const float64_t *pInA, *pInB; 51 | uint32_t blkCnt; 52 | float64_t accum, pA,pB; 53 | 54 | pInA = pSrcA; 55 | pInB = pSrcB; 56 | blkCnt = blockSize; 57 | 58 | accum = 0.0f; 59 | 60 | while(blkCnt > 0) 61 | { 62 | pA = *pInA++; 63 | pB = *pInB++; 64 | 65 | accum += pA * log(pB / pA); 66 | 67 | blkCnt--; 68 | } 69 | 70 | return(-accum); 71 | } 72 | 73 | /** 74 | * @} end of groupStats group 75 | */ 76 | 77 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 78 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_rogerstanimoto_distance.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | 4 | /* ---------------------------------------------------------------------- 5 | * Project: CMSIS DSP Library 6 | * Title: arm_rogerstanimoto_distance.c 7 | * Description: Roger Stanimoto distance between two vectors 8 | * 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 31 | #include 32 | #include 33 | 34 | 35 | 36 | extern void arm_boolean_distance_TT_FF_TF_FT(const uint32_t *pA 37 | , const uint32_t *pB 38 | , uint32_t numberOfBools 39 | , uint32_t *cTT 40 | , uint32_t *cFF 41 | , uint32_t *cTF 42 | , uint32_t *cFT 43 | ); 44 | 45 | 46 | /** 47 | @addtogroup BoolDist 48 | @{ 49 | */ 50 | 51 | /** 52 | * @brief Roger Stanimoto distance between two vectors 53 | * 54 | * @param[in] pA First vector of packed booleans 55 | * @param[in] pB Second vector of packed booleans 56 | * @param[in] numberOfBools Number of booleans 57 | * @return distance 58 | * 59 | */ 60 | 61 | float32_t arm_rogerstanimoto_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools) 62 | { 63 | uint32_t ctt=0,cff=0,ctf=0,cft=0,r; 64 | 65 | arm_boolean_distance_TT_FF_TF_FT(pA, pB, numberOfBools, &ctt,&cff, &ctf, &cft); 66 | 67 | r = 2*(ctf + cft); 68 | 69 | return(1.0*r / (r + ctt + cff)); 70 | } 71 | 72 | 73 | /** 74 | * @} end of BoolDist group 75 | */ 76 | 77 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 78 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/NN/Source/ConcatenationFunctions/arm_concatenation_s8_z.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2019 Arm Limited or its affiliates. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /* ---------------------------------------------------------------------- 20 | * Project: CMSIS NN Library 21 | * Title: arm_concatenation_s8_z.c 22 | * Description: s8 version of concatenation along the Z axis 23 | * 24 | * $Date: October 2019 25 | * $Revision: V.1.0.0 26 | * 27 | * Target Processor: Cortex-M cores 28 | * 29 | * -------------------------------------------------------------------- */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/NN/Include/arm_nnfunctions.h" 32 | 33 | /** 34 | * @ingroup groupNN 35 | */ 36 | 37 | /** 38 | * @addtogroup Concatenation 39 | * @{ 40 | */ 41 | 42 | /* 43 | * s8 version of concatenation along the Z axis 44 | * 45 | * Refer to header file for details. 46 | * 47 | */ 48 | void arm_concatenation_s8_z(const int8_t *input, 49 | const uint16_t input_x, 50 | const uint16_t input_y, 51 | const uint16_t input_z, 52 | const uint16_t input_w, 53 | int8_t *output, 54 | const uint16_t output_z, 55 | const uint32_t offset_z) 56 | { 57 | const uint32_t input_copy_size = input_x * input_y * input_z; 58 | const uint32_t output_stride = input_x * input_y * output_z; 59 | 60 | output += offset_z * (input_x * input_y); 61 | 62 | uint32_t i; 63 | 64 | for (i = 0; i < input_w; ++i) 65 | { 66 | memcpy(output, input, input_copy_size); 67 | input += input_copy_size; 68 | output += output_stride; 69 | } 70 | } 71 | 72 | /** 73 | * @} end of Concatenation group 74 | */ 75 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/kernels/internal/reference/quantize.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_QUANTIZE_H_ 16 | #define TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_QUANTIZE_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/common.h" 22 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/compatibility.h" 23 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/cppmath.h" 24 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/types.h" 25 | 26 | namespace tflite { 27 | 28 | namespace reference_ops { 29 | 30 | template 31 | inline void AffineQuantize(const tflite::QuantizationParams& op_params, 32 | const RuntimeShape& input_shape, 33 | const InputT* input_data, 34 | const RuntimeShape& output_shape, 35 | OutputT* output_data) { 36 | const int32 zero_point = op_params.zero_point; 37 | const double scale = op_params.scale; 38 | const int flat_size = MatchingFlatSize(input_shape, output_shape); 39 | static constexpr int32 min_val = std::numeric_limits::min(); 40 | static constexpr int32 max_val = std::numeric_limits::max(); 41 | 42 | for (int i = 0; i < flat_size; i++) { 43 | const InputT val = input_data[i]; 44 | int32 unclamped = 45 | static_cast(TfLiteRound(val / static_cast(scale))) + 46 | zero_point; 47 | int32 clamped = std::min(std::max(unclamped, min_val), max_val); 48 | output_data[i] = clamped; 49 | } 50 | } 51 | 52 | } // namespace reference_ops 53 | 54 | } // namespace tflite 55 | #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_REFERENCE_QUANTIZE_H_ 56 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_sokalmichener_distance.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | 4 | /* ---------------------------------------------------------------------- 5 | * Project: CMSIS DSP Library 6 | * Title: arm_sokalmichener_distance.c 7 | * Description: Sokal-Michener distance between two vectors 8 | * 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 31 | #include 32 | #include 33 | 34 | 35 | extern void arm_boolean_distance_TT_FF_TF_FT(const uint32_t *pA 36 | , const uint32_t *pB 37 | , uint32_t numberOfBools 38 | , uint32_t *cTT 39 | , uint32_t *cFF 40 | , uint32_t *cTF 41 | , uint32_t *cFT 42 | ); 43 | 44 | 45 | /** 46 | @addtogroup BoolDist 47 | @{ 48 | */ 49 | 50 | /** 51 | * @brief Sokal-Michener distance between two vectors 52 | * 53 | * @param[in] pA First vector of packed booleans 54 | * @param[in] pB Second vector of packed booleans 55 | * @param[in] numberOfBools Number of booleans 56 | * @return distance 57 | * 58 | */ 59 | 60 | float32_t arm_sokalmichener_distance(const uint32_t *pA, const uint32_t *pB, uint32_t numberOfBools) 61 | { 62 | uint32_t ctt=0,cff=0,cft=0,ctf=0; 63 | float32_t r,s; 64 | 65 | arm_boolean_distance_TT_FF_TF_FT(pA, pB, numberOfBools, &ctt, &cff, &ctf, &cft); 66 | 67 | r = 2.0*(ctf + cft); 68 | s = 1.0*(cff + ctt); 69 | 70 | return(r / (s+r)); 71 | } 72 | 73 | 74 | /** 75 | * @} end of BoolDist group 76 | */ 77 | 78 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 79 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/NN/Source/SoftmaxFunctions/arm_softmax_with_batch_q7.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2019 Arm Limited or its affiliates. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /* ---------------------------------------------------------------------- 20 | * Project: CMSIS NN Library 21 | * Title: arm_softmax_with_batch_q7.c 22 | * Description: Q7 softmax function 23 | * 24 | * $Date: 05. August 2019 25 | * $Revision: V.1.0.0 26 | * 27 | * Target Processor: Cortex-M and Cortex-A cores 28 | * 29 | * -------------------------------------------------------------------- */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | #include "edge-impulse-sdk/CMSIS/NN/Include/arm_nnfunctions.h" 33 | 34 | /** 35 | * @ingroup groupNN 36 | */ 37 | 38 | /** 39 | * @addtogroup Softmax 40 | * @{ 41 | */ 42 | 43 | /** 44 | * @brief Q7 softmax function with batch parameter 45 | * @param[in] vec_in pointer to input vector 46 | * @param[in] nb_batches number of batches 47 | * @param[in] dim_vec input vector dimention 48 | * @param[out] p_out pointer to output vector 49 | * 50 | * @details 51 | * 52 | * Here, instead of typical natural logarithm e based softmax, we use 53 | * 2-based softmax here, i.e.,: 54 | * 55 | * y_i = 2^(x_i) / sum(2^x_j) 56 | * 57 | * The relative output will be different here. 58 | * But mathematically, the gradient will be the same 59 | * with a log(2) scaling factor. 60 | * 61 | */ 62 | 63 | void arm_softmax_with_batch_q7(const q7_t * vec_in, const uint16_t nb_batches,const uint16_t dim_vec, q7_t * p_out ) 64 | { 65 | for(int i=0; i> 2; 48 | q31_t in; 49 | 50 | while (cnt > 0l) 51 | { 52 | q31_t value = arm_nn_read_q7x4_ia(&pV); 53 | v1 = __SXTB16(__ROR(value, 8)); 54 | v2 = __SXTB16(value); 55 | #ifndef ARM_MATH_BIG_ENDIAN 56 | 57 | vo2 = __PKHTB(v1, v2, 16); 58 | vo1 = __PKHBT(v2, v1, 16); 59 | 60 | #else 61 | 62 | vo1 = __PKHTB(v1, v2, 16); 63 | vo2 = __PKHBT(v2, v1, 16); 64 | 65 | #endif 66 | 67 | in = arm_nn_read_q15x2(pCnt); 68 | write_q15x2_ia(&pCnt, __QADD16(vo1, in)); 69 | 70 | in = arm_nn_read_q15x2(pCnt); 71 | write_q15x2_ia(&pCnt, __QADD16(vo2, in)); 72 | 73 | cnt--; 74 | } 75 | cnt = length & 0x3; 76 | while (cnt > 0l) 77 | { 78 | *pCnt++ += *pV++; 79 | cnt--; 80 | } 81 | } 82 | 83 | /** 84 | * @} end of NNBasicMath group 85 | */ 86 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/core/api/error_reporter.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_ 16 | #define TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_ 17 | 18 | #include 19 | 20 | namespace tflite { 21 | 22 | /// A functor that reports error to supporting system. Invoked similar to 23 | /// printf. 24 | /// 25 | /// Usage: 26 | /// ErrorReporter foo; 27 | /// foo.Report("test %d", 5); 28 | /// or 29 | /// va_list args; 30 | /// foo.Report("test %d", args); // where args is va_list 31 | /// 32 | /// Subclass ErrorReporter to provide another reporting destination. 33 | /// For example, if you have a GUI program, you might redirect to a buffer 34 | /// that drives a GUI error log box. 35 | class ErrorReporter { 36 | public: 37 | virtual ~ErrorReporter() {} 38 | virtual int Report(const char* format, va_list args) = 0; 39 | int Report(const char* format, ...); 40 | int ReportError(void*, const char* format, ...); 41 | }; 42 | 43 | } // namespace tflite 44 | 45 | // You should not make bare calls to the error reporter, instead use the 46 | // TF_LITE_REPORT_ERROR macro, since this allows message strings to be 47 | // stripped when the binary size has to be optimized. If you are looking to 48 | // reduce binary size, define TF_LITE_STRIP_ERROR_STRINGS when compiling and 49 | // every call will be stubbed out, taking no memory. 50 | #ifndef TF_LITE_STRIP_ERROR_STRINGS 51 | #define TF_LITE_REPORT_ERROR(reporter, ...) \ 52 | do { \ 53 | static_cast(reporter)->Report(__VA_ARGS__); \ 54 | } while (false) 55 | #else // TF_LITE_STRIP_ERROR_STRINGS 56 | #define TF_LITE_REPORT_ERROR(reporter, ...) 57 | #endif // TF_LITE_STRIP_ERROR_STRINGS 58 | 59 | #endif // TENSORFLOW_LITE_CORE_API_ERROR_REPORTER_H_ 60 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/FilteringFunctions/arm_fir_lattice_init_q15.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_fir_lattice_init_q15.c 6 | * Description: Q15 FIR Lattice filter initialization function 7 | * 8 | * $Date: 18. March 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | 33 | /** 34 | @ingroup groupFilters 35 | */ 36 | 37 | /** 38 | @addtogroup FIR_Lattice 39 | @{ 40 | */ 41 | 42 | /** 43 | @brief Initialization function for the Q15 FIR lattice filter. 44 | @param[in] S points to an instance of the Q15 FIR lattice structure 45 | @param[in] numStages number of filter stages 46 | @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages 47 | @param[in] pState points to the state buffer. The array is of length numStages 48 | @return none 49 | */ 50 | 51 | void arm_fir_lattice_init_q15( 52 | arm_fir_lattice_instance_q15 * S, 53 | uint16_t numStages, 54 | const q15_t * pCoeffs, 55 | q15_t * pState) 56 | { 57 | /* Assign filter taps */ 58 | S->numStages = numStages; 59 | 60 | /* Assign coefficient pointer */ 61 | S->pCoeffs = pCoeffs; 62 | 63 | /* Clear state buffer and size is always numStages */ 64 | memset(pState, 0, (numStages) * sizeof(q15_t)); 65 | 66 | /* Assign state pointer */ 67 | S->pState = pState; 68 | } 69 | 70 | /** 71 | @} end of FIR_Lattice group 72 | */ 73 | 74 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 75 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/FilteringFunctions/arm_fir_lattice_init_q31.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_fir_lattice_init_q31.c 6 | * Description: Q31 FIR lattice filter initialization function 7 | * 8 | * $Date: 18. March 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | 33 | /** 34 | @ingroup groupFilters 35 | */ 36 | 37 | /** 38 | @addtogroup FIR_Lattice 39 | @{ 40 | */ 41 | 42 | /** 43 | @brief Initialization function for the Q31 FIR lattice filter. 44 | @param[in] S points to an instance of the Q31 FIR lattice structure 45 | @param[in] numStages number of filter stages 46 | @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages 47 | @param[in] pState points to the state buffer. The array is of length numStages 48 | @return none 49 | */ 50 | 51 | void arm_fir_lattice_init_q31( 52 | arm_fir_lattice_instance_q31 * S, 53 | uint16_t numStages, 54 | const q31_t * pCoeffs, 55 | q31_t * pState) 56 | { 57 | /* Assign filter taps */ 58 | S->numStages = numStages; 59 | 60 | /* Assign coefficient pointer */ 61 | S->pCoeffs = pCoeffs; 62 | 63 | /* Clear state buffer and size is always numStages */ 64 | memset(pState, 0, (numStages) * sizeof(q31_t)); 65 | 66 | /* Assign state pointer */ 67 | S->pState = pState; 68 | } 69 | 70 | /** 71 | @} end of FIR_Lattice group 72 | */ 73 | 74 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 75 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/DistanceFunctions/arm_correlation_distance_f32.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | 4 | /* ---------------------------------------------------------------------- 5 | * Project: CMSIS DSP Library 6 | * Title: arm_correlation_distance_f32.c 7 | * Description: Correlation distance between two vectors 8 | * 9 | * 10 | * Target Processor: Cortex-M cores 11 | * -------------------------------------------------------------------- */ 12 | /* 13 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 14 | * 15 | * SPDX-License-Identifier: Apache-2.0 16 | * 17 | * Licensed under the Apache License, Version 2.0 (the License); you may 18 | * not use this file except in compliance with the License. 19 | * You may obtain a copy of the License at 20 | * 21 | * www.apache.org/licenses/LICENSE-2.0 22 | * 23 | * Unless required by applicable law or agreed to in writing, software 24 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 25 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | * See the License for the specific language governing permissions and 27 | * limitations under the License. 28 | */ 29 | 30 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 31 | #include 32 | #include 33 | 34 | 35 | 36 | /** 37 | @addtogroup FloatDist 38 | @{ 39 | */ 40 | 41 | 42 | /** 43 | * @brief Correlation distance between two vectors 44 | * 45 | * The input vectors are modified in place ! 46 | * 47 | * @param[in] pA First vector 48 | * @param[in] pB Second vector 49 | * @param[in] blockSize vector length 50 | * @return distance 51 | * 52 | */ 53 | 54 | float32_t arm_correlation_distance_f32(float32_t *pA,float32_t *pB, uint32_t blockSize) 55 | { 56 | float32_t ma,mb,pwra,pwrb,dot,tmp; 57 | 58 | arm_mean_f32(pA, blockSize, &ma); 59 | arm_mean_f32(pB, blockSize, &mb); 60 | 61 | arm_offset_f32(pA, -ma, pA, blockSize); 62 | arm_offset_f32(pB, -mb, pB, blockSize); 63 | 64 | arm_power_f32(pA, blockSize, &pwra); 65 | arm_power_f32(pB, blockSize, &pwrb); 66 | 67 | arm_dot_prod_f32(pA,pB,blockSize,&dot); 68 | 69 | dot = dot / blockSize; 70 | pwra = pwra / blockSize; 71 | pwrb = pwrb / blockSize; 72 | 73 | arm_sqrt_f32(pwra * pwrb,&tmp); 74 | 75 | return(1.0f - dot / tmp); 76 | 77 | 78 | } 79 | 80 | 81 | 82 | /** 83 | * @} end of FloatDist group 84 | */ 85 | 86 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 87 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/MatrixFunctions/arm_mat_init_f32.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_mat_init_f32.c 6 | * Description: Floating-point matrix initialization 7 | * 8 | * $Date: 18. March 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | 33 | /** 34 | @ingroup groupMatrix 35 | */ 36 | 37 | /** 38 | @defgroup MatrixInit Matrix Initialization 39 | 40 | Initializes the underlying matrix data structure. 41 | The functions set the numRows, 42 | numCols, and pData fields 43 | of the matrix data structure. 44 | */ 45 | 46 | /** 47 | @addtogroup MatrixInit 48 | @{ 49 | */ 50 | 51 | /** 52 | @brief Floating-point matrix initialization. 53 | @param[in,out] S points to an instance of the floating-point matrix structure 54 | @param[in] nRows number of rows in the matrix 55 | @param[in] nColumns number of columns in the matrix 56 | @param[in] pData points to the matrix data array 57 | @return none 58 | */ 59 | 60 | void arm_mat_init_f32( 61 | arm_matrix_instance_f32 * S, 62 | uint16_t nRows, 63 | uint16_t nColumns, 64 | float32_t * pData) 65 | { 66 | /* Assign Number of Rows */ 67 | S->numRows = nRows; 68 | 69 | /* Assign Number of Columns */ 70 | S->numCols = nColumns; 71 | 72 | /* Assign Data pointer */ 73 | S->pData = pData; 74 | } 75 | 76 | /** 77 | @} end of MatrixInit group 78 | */ 79 | 80 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 81 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/kernels/op_macros.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_KERNELS_OP_MACROS_H_ 16 | #define TENSORFLOW_LITE_KERNELS_OP_MACROS_H_ 17 | 18 | // If we're on a platform without standard IO functions, fall back to a 19 | // non-portable function. 20 | #ifdef TF_LITE_MCU_DEBUG_LOG 21 | 22 | #include "edge-impulse-sdk/tensorflow/lite/micro/debug_log.h" 23 | 24 | #define DEBUG_LOG(x) \ 25 | do { \ 26 | DebugLog(x); \ 27 | } while (0) 28 | 29 | inline void InfiniteLoop() { 30 | DEBUG_LOG("HALTED\n"); 31 | while (1) { 32 | } 33 | } 34 | 35 | #define TFLITE_ABORT InfiniteLoop(); 36 | 37 | #else // TF_LITE_MCU_DEBUG_LOG 38 | 39 | #include 40 | #include 41 | 42 | #define DEBUG_LOG(x) \ 43 | do { \ 44 | fprintf(stderr, "%s", (x)); \ 45 | } while (0) 46 | 47 | #define TFLITE_ABORT abort() 48 | 49 | #endif // TF_LITE_MCU_DEBUG_LOG 50 | 51 | // Patched by Edge Impulse, skip over asserts on Arduino 52 | // https://github.com/tensorflow/tensorflow/commit/6d5f02b47af2efb5ed2f5b4ccf34d4abecf8cfde 53 | #if defined(NDEBUG) || defined(ARDUINO) 54 | #define TFLITE_ASSERT_FALSE (static_cast(0)) 55 | #else 56 | #define TFLITE_ASSERT_FALSE TFLITE_ABORT 57 | #endif 58 | 59 | #define TF_LITE_FATAL(msg) \ 60 | do { \ 61 | DEBUG_LOG(msg); \ 62 | DEBUG_LOG("\nFATAL\n"); \ 63 | TFLITE_ABORT; \ 64 | } while (0) 65 | 66 | #define TF_LITE_ASSERT(x) \ 67 | do { \ 68 | if (!(x)) TF_LITE_FATAL(#x); \ 69 | } while (0) 70 | 71 | #define TF_LITE_ASSERT_EQ(x, y) \ 72 | do { \ 73 | if ((x) != (y)) TF_LITE_FATAL(#x " didn't equal " #y); \ 74 | } while (0) 75 | 76 | #endif // TENSORFLOW_LITE_KERNELS_OP_MACROS_H_ 77 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/FilteringFunctions/arm_fir_lattice_init_f32.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_fir_lattice_init_f32.c 6 | * Description: Floating-point FIR Lattice filter initialization function 7 | * 8 | * $Date: 18. March 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | 33 | /** 34 | @ingroup groupFilters 35 | */ 36 | 37 | /** 38 | @addtogroup FIR_Lattice 39 | @{ 40 | */ 41 | 42 | /** 43 | @brief Initialization function for the floating-point FIR lattice filter. 44 | @param[in] S points to an instance of the floating-point FIR lattice structure 45 | @param[in] numStages number of filter stages 46 | @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages 47 | @param[in] pState points to the state buffer. The array is of length numStages 48 | @return none 49 | */ 50 | 51 | void arm_fir_lattice_init_f32( 52 | arm_fir_lattice_instance_f32 * S, 53 | uint16_t numStages, 54 | const float32_t * pCoeffs, 55 | float32_t * pState) 56 | { 57 | /* Assign filter taps */ 58 | S->numStages = numStages; 59 | 60 | /* Assign coefficient pointer */ 61 | S->pCoeffs = pCoeffs; 62 | 63 | /* Clear state buffer and size is always numStages */ 64 | memset(pState, 0, (numStages) * sizeof(float32_t)); 65 | 66 | /* Assign state pointer */ 67 | S->pState = pState; 68 | } 69 | 70 | /** 71 | @} end of FIR_Lattice group 72 | */ 73 | 74 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 75 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/NN/Source/NNSupportFunctions/arm_nn_add_q7.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2010-2018 Arm Limited or its affiliates. All rights reserved. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the License); you may 7 | * not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | /* ---------------------------------------------------------------------- 20 | * Project: CMSIS NN Library 21 | * Title: arm_nn_add_q7.c 22 | * Description: Non saturating addition of elements of a q7 vector. 23 | * 24 | * $Date: July 2019 25 | * $Revision: V.1.0.0 26 | * 27 | * Target Processor: Cortex-M cores 28 | * 29 | * -------------------------------------------------------------------- */ 30 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 31 | #include "edge-impulse-sdk/CMSIS/NN/Include/arm_nnfunctions.h" 32 | 33 | /** 34 | * @ingroup groupSupport 35 | */ 36 | 37 | /** 38 | * @addtogroup NNBasicMath 39 | * @{ 40 | */ 41 | 42 | void arm_nn_add_q7(const q7_t *input, q31_t *output, uint32_t block_size) 43 | { 44 | uint32_t block_count; 45 | q31_t result = 0; 46 | #if defined(ARM_MATH_DSP) 47 | /* Loop unrolling: Compute 4 outputs at a time */ 48 | block_count = block_size >> 2U; 49 | 50 | while (block_count > 0U) 51 | { 52 | const int32_t mult_q15x2 = (1UL << 16) | 1UL; 53 | q31_t in_q7x4 = arm_nn_read_q7x4_ia(&input); 54 | q31_t temp_q15x2 = __SXTAB16(__SXTB16(in_q7x4), __ROR(in_q7x4, 8)); 55 | 56 | result = __SMLAD(temp_q15x2, mult_q15x2, result); 57 | 58 | /* Decrement loop counter */ 59 | block_count--; 60 | } 61 | 62 | /* Loop unrolling: Compute remaining outputs */ 63 | block_count = block_size & 0x3; 64 | #else 65 | block_count = block_size; 66 | #endif 67 | while (block_count > 0U) 68 | { 69 | /* Add and store result in destination buffer. */ 70 | result += *input++; 71 | 72 | /* Decrement loop counter */ 73 | block_count--; 74 | } 75 | 76 | *output = result; 77 | } 78 | 79 | /** 80 | * @} end of NNBasicMath group 81 | */ 82 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/kernels/neg.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/reference/neg.h" 17 | 18 | #include "edge-impulse-sdk/tensorflow/lite/c/common.h" 19 | #include "edge-impulse-sdk/tensorflow/lite/kernels/internal/tensor_ctypes.h" 20 | #include "edge-impulse-sdk/tensorflow/lite/kernels/kernel_util.h" 21 | 22 | namespace tflite { 23 | namespace ops { 24 | namespace micro { 25 | namespace neg { 26 | 27 | constexpr int kInputTensor = 0; 28 | constexpr int kOutputTensor = 0; 29 | 30 | TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { 31 | const TfLiteTensor* input = GetInput(context, node, kInputTensor); 32 | TfLiteTensor* output = GetOutput(context, node, kOutputTensor); 33 | switch (input->type) { 34 | // TODO(wangtz): handle for kTfLiteInt8 35 | case kTfLiteFloat32: 36 | reference_ops::Negate(GetTensorShape(input), GetTensorData(input), 37 | GetTensorShape(output), 38 | GetTensorData(output)); 39 | break; 40 | default: 41 | TF_LITE_KERNEL_LOG(context, "Type %s (%d) not supported.", 42 | TfLiteTypeGetName(input->type), input->type); 43 | return kTfLiteError; 44 | } 45 | return kTfLiteOk; 46 | } 47 | 48 | } // namespace neg 49 | 50 | TfLiteRegistration* Register_NEG() { 51 | static TfLiteRegistration r = {/*init=*/nullptr, 52 | /*free=*/nullptr, 53 | /*prepare=*/nullptr, 54 | /*invoke=*/neg::Eval, 55 | /*profiling_string=*/nullptr, 56 | /*builtin_code=*/0, 57 | /*custom_name=*/nullptr, 58 | /*version=*/0}; 59 | return &r; 60 | } 61 | 62 | } // namespace micro 63 | } // namespace ops 64 | } // namespace tflite 65 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/type_to_tflitetype.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_LITE_TYPE_TO_TFLITETYPE_H_ 16 | #define TENSORFLOW_LITE_TYPE_TO_TFLITETYPE_H_ 17 | 18 | // Arduino build defines abs as a macro here. That is invalid C++, and breaks 19 | // libc++'s header, undefine it. 20 | #ifdef abs 21 | #undef abs 22 | #endif 23 | 24 | #include 25 | #include 26 | 27 | #include "edge-impulse-sdk/tensorflow/lite/c/common.h" 28 | 29 | namespace tflite { 30 | 31 | // Map statically from a c++ type to a TfLiteType. Used in interpreter for safe 32 | // casts. 33 | template 34 | constexpr TfLiteType typeToTfLiteType() { 35 | return kTfLiteNoType; 36 | } 37 | template <> 38 | constexpr TfLiteType typeToTfLiteType() { 39 | return kTfLiteInt32; 40 | } 41 | template <> 42 | constexpr TfLiteType typeToTfLiteType() { 43 | return kTfLiteInt16; 44 | } 45 | template <> 46 | constexpr TfLiteType typeToTfLiteType() { 47 | return kTfLiteInt64; 48 | } 49 | template <> 50 | constexpr TfLiteType typeToTfLiteType() { 51 | return kTfLiteFloat32; 52 | } 53 | template <> 54 | constexpr TfLiteType typeToTfLiteType() { 55 | return kTfLiteUInt8; 56 | } 57 | template <> 58 | constexpr TfLiteType typeToTfLiteType() { 59 | return kTfLiteInt8; 60 | } 61 | template <> 62 | constexpr TfLiteType typeToTfLiteType() { 63 | return kTfLiteBool; 64 | } 65 | template <> 66 | constexpr TfLiteType typeToTfLiteType>() { 67 | return kTfLiteComplex64; 68 | } 69 | template <> 70 | constexpr TfLiteType typeToTfLiteType() { 71 | return kTfLiteString; 72 | } 73 | template <> 74 | constexpr TfLiteType typeToTfLiteType() { 75 | return kTfLiteFloat16; 76 | } 77 | template <> 78 | constexpr TfLiteType typeToTfLiteType() { 79 | return kTfLiteFloat64; 80 | } 81 | } // namespace tflite 82 | #endif // TENSORFLOW_LITE_TYPE_TO_TFLITETYPE_H_ 83 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/all_ops_resolver.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | Licensed under the Apache License, Version 2.0 (the "License"); 3 | you may not use this file except in compliance with the License. 4 | You may obtain a copy of the License at 5 | http://www.apache.org/licenses/LICENSE-2.0 6 | Unless required by applicable law or agreed to in writing, software 7 | distributed under the License is distributed on an "AS IS" BASIS, 8 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | See the License for the specific language governing permissions and 10 | limitations under the License. 11 | ==============================================================================*/ 12 | 13 | #include "edge-impulse-sdk/tensorflow/lite/micro/all_ops_resolver.h" 14 | 15 | #include "edge-impulse-sdk/tensorflow/lite/micro/kernels/micro_ops.h" 16 | 17 | namespace tflite { 18 | namespace ops { 19 | namespace micro { 20 | namespace custom { 21 | TfLiteRegistration* Register_ETHOSU(); 22 | const char* GetString_ETHOSU(); 23 | } // namespace custom 24 | } // namespace micro 25 | } // namespace ops 26 | 27 | AllOpsResolver::AllOpsResolver() { 28 | // Please keep this list of Builtin Operators in alphabetical order. 29 | AddAbs(); 30 | AddAdd(); 31 | AddArgMax(); 32 | AddArgMin(); 33 | AddAveragePool2D(); 34 | AddCeil(); 35 | AddConcatenation(); 36 | AddConv2D(); 37 | AddCos(); 38 | AddDepthwiseConv2D(); 39 | AddDequantize(); 40 | AddEqual(); 41 | AddFloor(); 42 | AddFullyConnected(); 43 | AddGreater(); 44 | AddGreaterEqual(); 45 | AddL2Normalization(); 46 | AddLess(); 47 | AddLessEqual(); 48 | AddLog(); 49 | AddLogicalAnd(); 50 | AddLogicalNot(); 51 | AddLogicalOr(); 52 | AddLogistic(); 53 | AddMaximum(); 54 | AddMaxPool2D(); 55 | AddMean(); 56 | AddMinimum(); 57 | AddMul(); 58 | AddNeg(); 59 | AddNotEqual(); 60 | AddPack(); 61 | AddPad(); 62 | AddPadV2(); 63 | AddPrelu(); 64 | AddQuantize(); 65 | AddRelu(); 66 | AddRelu6(); 67 | AddReshape(); 68 | AddResizeNearestNeighbor(); 69 | AddRound(); 70 | AddRsqrt(); 71 | AddSin(); 72 | AddSoftmax(); 73 | AddSplit(); 74 | AddSqrt(); 75 | AddSquare(); 76 | AddStridedSlice(); 77 | AddSub(); 78 | AddSvdf(); 79 | AddTanh(); 80 | AddUnpack(); 81 | 82 | // TODO(b/159644355): Figure out if custom Ops belong in AllOpsResolver. 83 | TfLiteRegistration* registration = 84 | tflite::ops::micro::custom::Register_ETHOSU(); 85 | if (registration) { 86 | AddCustom(tflite::ops::micro::custom::GetString_ETHOSU(), registration); 87 | } 88 | } 89 | 90 | } // namespace tflite 91 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/kernels/scratch_buffers.h: -------------------------------------------------------------------------------- 1 | // Patched by Edge Impulse to include reference, CMSIS-NN and ARC kernels 2 | #include "../../../../classifier/ei_classifier_config.h" 3 | #if EI_CLASSIFIER_TFLITE_ENABLE_ARC == 1 4 | /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | ==============================================================================*/ 18 | 19 | #ifndef TENSORFLOW_LITE_MICRO_ARC_SCRATCH_BUFFERS_H_ 20 | #define TENSORFLOW_LITE_MICRO_ARC_SCRATCH_BUFFERS_H_ 21 | 22 | #include "mli_api.h" // NOLINT 23 | #include "edge-impulse-sdk/tensorflow/lite/c/common.h" 24 | 25 | namespace tflite { 26 | namespace ops { 27 | namespace micro { 28 | 29 | void init_arc_scratch_buffers(void); 30 | void* get_arc_scratch_buffer(int size); // Function to assign fast memory 31 | // from one of 3 scratch buffers. 32 | 33 | void get_arc_scratch_buffer_max_size(int* size); 34 | void get_arc_scratch_buffer_two_max_sizes(int* size1, int* size2); 35 | 36 | static inline bool inside_arc_dccm(void* p) { 37 | #if core_config_dccm_present 38 | return ((unsigned)p >= core_config_dccm_base) && 39 | ((unsigned)p < core_config_dccm_base + core_config_dccm_size); 40 | #else 41 | return false; 42 | #endif 43 | } 44 | 45 | static inline bool inside_arc_xccm(void* p) { 46 | #if core_config_xy 47 | return ((unsigned)p >= core_config_xy_x_base) && 48 | ((unsigned)p < core_config_xy_x_base + core_config_xy_size); 49 | #else 50 | return false; 51 | #endif 52 | } 53 | 54 | static inline bool inside_arc_yccm(void* p) { 55 | #if core_config_xy 56 | return ((unsigned)p >= core_config_xy_y_base) && 57 | ((unsigned)p < core_config_xy_y_base + core_config_xy_size); 58 | #else 59 | return false; 60 | #endif 61 | } 62 | 63 | static inline bool inside_arc_ccm(void* p) { 64 | return inside_arc_dccm(p) || inside_arc_xccm(p) || inside_arc_yccm(p); 65 | } 66 | 67 | } // namespace micro 68 | } // namespace ops 69 | } // namespace tflite 70 | 71 | #endif // TENSORFLOW_LITE_MICRO_ARC_SCRATCH_BUFFERS_H_ 72 | 73 | #endif // EI_CLASSIFIER_TFLITE_ENABLE_ARC == 1 74 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/recording_micro_interpreter.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_RECORDING_MICRO_INTERPRETER_H_ 17 | #define TENSORFLOW_LITE_MICRO_RECORDING_MICRO_INTERPRETER_H_ 18 | 19 | #include "edge-impulse-sdk/tensorflow/lite/micro/micro_interpreter.h" 20 | #include "edge-impulse-sdk/tensorflow/lite/micro/recording_micro_allocator.h" 21 | 22 | namespace tflite { 23 | 24 | // Utility subclass that enables internal recordings of the MicroInterpreter. 25 | // This class should be used to audit and analyze memory arena usage for a given 26 | // model and interpreter. 27 | // 28 | // After construction and the first Invoke() or AllocateTensors() call - the 29 | // memory usage is recorded and available through the GetMicroAllocator() 30 | // function. See RecordingMicroAlloctor for more details on what is currently 31 | // recorded from arena allocations. 32 | // 33 | // It is recommended for users to increase the tensor arena size by at least 1kb 34 | // to ensure enough additional memory is available for internal recordings. 35 | class RecordingMicroInterpreter : public MicroInterpreter { 36 | public: 37 | RecordingMicroInterpreter(const Model* model, 38 | const MicroOpResolver& op_resolver, 39 | uint8_t* tensor_arena, size_t tensor_arena_size, 40 | ErrorReporter* error_reporter) 41 | : MicroInterpreter(model, op_resolver, 42 | RecordingMicroAllocator::Create( 43 | tensor_arena, tensor_arena_size, error_reporter), 44 | error_reporter), 45 | recording_micro_allocator_( 46 | static_cast(allocator())) {} 47 | 48 | const RecordingMicroAllocator& GetMicroAllocator() const { 49 | return recording_micro_allocator_; 50 | } 51 | 52 | private: 53 | const RecordingMicroAllocator& recording_micro_allocator_; 54 | }; 55 | 56 | } // namespace tflite 57 | 58 | #endif // TENSORFLOW_LITE_MICRO_RECORDING_MICRO_INTERPRETER_H_ 59 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/micro/recording_simple_memory_allocator.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2020 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_LITE_MICRO_RECORDING_SIMPLE_MEMORY_ALLOCATOR_H_ 17 | #define TENSORFLOW_LITE_MICRO_RECORDING_SIMPLE_MEMORY_ALLOCATOR_H_ 18 | 19 | #include "edge-impulse-sdk/tensorflow/lite/micro/compatibility.h" 20 | #include "edge-impulse-sdk/tensorflow/lite/micro/simple_memory_allocator.h" 21 | 22 | namespace tflite { 23 | 24 | // Utility class used to log allocations of a SimpleMemoryAllocator. Should only 25 | // be used in debug/evaluation settings or unit tests to evaluate allocation 26 | // usage. 27 | class RecordingSimpleMemoryAllocator : public SimpleMemoryAllocator { 28 | public: 29 | RecordingSimpleMemoryAllocator(ErrorReporter* error_reporter, 30 | uint8_t* buffer_head, size_t buffer_size); 31 | // TODO(b/157615197): Cleanup constructors/destructor and use factory 32 | // functions. 33 | ~RecordingSimpleMemoryAllocator() override; 34 | 35 | static RecordingSimpleMemoryAllocator* Create(ErrorReporter* error_reporter, 36 | uint8_t* buffer_head, 37 | size_t buffer_size); 38 | 39 | // Returns the number of bytes requested from the head or tail. 40 | size_t GetRequestedBytes() const; 41 | 42 | // Returns the number of bytes actually allocated from the head or tail. This 43 | // value will be >= to the number of requested bytes due to padding and 44 | // alignment. 45 | size_t GetUsedBytes() const; 46 | 47 | // Returns the number of alloc calls from the head or tail. 48 | size_t GetAllocatedCount() const; 49 | 50 | uint8_t* AllocateFromHead(size_t size, size_t alignment) override; 51 | uint8_t* AllocateFromTail(size_t size, size_t alignment) override; 52 | 53 | private: 54 | size_t requested_bytes_; 55 | size_t used_bytes_; 56 | size_t alloc_count_; 57 | 58 | TF_LITE_REMOVE_VIRTUAL_DELETE 59 | }; 60 | 61 | } // namespace tflite 62 | 63 | #endif // TENSORFLOW_LITE_MICRO_RECORDING_SIMPLE_MEMORY_ALLOCATOR_H_ 64 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/tensorflow/lite/core/api/op_resolver.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "edge-impulse-sdk/tensorflow/lite/core/api/op_resolver.h" 17 | 18 | #include "edge-impulse-sdk/third_party/flatbuffers/include/flatbuffers/flatbuffers.h" // from @flatbuffers 19 | #include "edge-impulse-sdk/tensorflow/lite/c/common.h" 20 | #include "edge-impulse-sdk/tensorflow/lite/core/api/error_reporter.h" 21 | 22 | namespace tflite { 23 | 24 | TfLiteStatus GetRegistrationFromOpCode( 25 | const OperatorCode* opcode, const OpResolver& op_resolver, 26 | ErrorReporter* error_reporter, const TfLiteRegistration** registration) { 27 | TfLiteStatus status = kTfLiteOk; 28 | *registration = nullptr; 29 | auto builtin_code = opcode->builtin_code(); 30 | int version = opcode->version(); 31 | 32 | if (builtin_code > BuiltinOperator_MAX || 33 | builtin_code < BuiltinOperator_MIN) { 34 | TF_LITE_REPORT_ERROR( 35 | error_reporter, 36 | "Op builtin_code out of range: %d. Are you using old TFLite binary " 37 | "with newer model?", 38 | builtin_code); 39 | status = kTfLiteError; 40 | } else if (builtin_code != BuiltinOperator_CUSTOM) { 41 | *registration = op_resolver.FindOp(builtin_code, version); 42 | if (*registration == nullptr) { 43 | TF_LITE_REPORT_ERROR( 44 | error_reporter, 45 | "Didn't find op for builtin opcode '%s' version '%d'\n", 46 | EnumNameBuiltinOperator(builtin_code), version); 47 | status = kTfLiteError; 48 | } 49 | } else if (!opcode->custom_code()) { 50 | TF_LITE_REPORT_ERROR( 51 | error_reporter, 52 | "Operator with CUSTOM builtin_code has no custom_code.\n"); 53 | status = kTfLiteError; 54 | } else { 55 | const char* name = opcode->custom_code()->c_str(); 56 | *registration = op_resolver.FindOp(name, version); 57 | if (*registration == nullptr) { 58 | // Do not report error for unresolved custom op, we do the final check 59 | // while preparing ops. 60 | status = kTfLiteError; 61 | } 62 | } 63 | return status; 64 | } 65 | 66 | } // namespace tflite 67 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/ControllerFunctions/arm_pid_init_f32.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_pid_init_f32.c 6 | * Description: Floating-point PID Control initialization function 7 | * 8 | * $Date: 18. March 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | 33 | /** 34 | @addtogroup PID 35 | @{ 36 | */ 37 | 38 | /** 39 | @brief Initialization function for the floating-point PID Control. 40 | @param[in,out] S points to an instance of the PID structure 41 | @param[in] resetStateFlag 42 | - value = 0: no change in state 43 | - value = 1: reset state 44 | @return none 45 | 46 | @par Details 47 | The resetStateFlag specifies whether to set state to zero or not. \n 48 | The function computes the structure fields: A0, A1 A2 49 | using the proportional gain( \c Kp), integral gain( \c Ki) and derivative gain( \c Kd) 50 | also sets the state variables to all zeros. 51 | */ 52 | 53 | void arm_pid_init_f32( 54 | arm_pid_instance_f32 * S, 55 | int32_t resetStateFlag) 56 | { 57 | /* Derived coefficient A0 */ 58 | S->A0 = S->Kp + S->Ki + S->Kd; 59 | 60 | /* Derived coefficient A1 */ 61 | S->A1 = (-S->Kp) - ((float32_t) 2.0f * S->Kd); 62 | 63 | /* Derived coefficient A2 */ 64 | S->A2 = S->Kd; 65 | 66 | /* Check whether state needs reset or not */ 67 | if (resetStateFlag) 68 | { 69 | /* Reset state to zero, The size will be always 3 samples */ 70 | memset(S->state, 0, 3U * sizeof(float32_t)); 71 | } 72 | 73 | } 74 | 75 | /** 76 | @} end of PID group 77 | */ 78 | 79 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 80 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/SVMFunctions/arm_svm_linear_init_f32.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_svm_linear_init_f32.c 6 | * Description: SVM Linear Instance Initialization 7 | * 8 | * 9 | * Target Processor: Cortex-M and Cortex-A cores 10 | * -------------------------------------------------------------------- */ 11 | /* 12 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 13 | * 14 | * SPDX-License-Identifier: Apache-2.0 15 | * 16 | * Licensed under the Apache License, Version 2.0 (the License); you may 17 | * not use this file except in compliance with the License. 18 | * You may obtain a copy of the License at 19 | * 20 | * www.apache.org/licenses/LICENSE-2.0 21 | * 22 | * Unless required by applicable law or agreed to in writing, software 23 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 24 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 | * See the License for the specific language governing permissions and 26 | * limitations under the License. 27 | */ 28 | 29 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 30 | #include 31 | #include 32 | 33 | /** 34 | * @defgroup groupSVM SVM Functions 35 | * 36 | */ 37 | 38 | 39 | /** 40 | * @addtogroup groupSVM 41 | * @{ 42 | */ 43 | 44 | 45 | /** 46 | * @brief SVM linear instance init function 47 | * 48 | * Classes are integer used as output of the function (instead of having -1,1 49 | * as class values). 50 | * 51 | * @param[in] S Parameters for the SVM function 52 | * @param[in] nbOfSupportVectors Number of support vectors 53 | * @param[in] vectorDimension Dimension of vector space 54 | * @param[in] intercept Intercept 55 | * @param[in] dualCoefficients Array of dual coefficients 56 | * @param[in] supportVectors Array of support vectors 57 | * @param[in] classes Array of 2 classes ID 58 | * @return none. 59 | * 60 | */ 61 | 62 | 63 | void arm_svm_linear_init_f32(arm_svm_linear_instance_f32 *S, 64 | uint32_t nbOfSupportVectors, 65 | uint32_t vectorDimension, 66 | float32_t intercept, 67 | const float32_t *dualCoefficients, 68 | const float32_t *supportVectors, 69 | const int32_t *classes) 70 | { 71 | S->nbOfSupportVectors = nbOfSupportVectors; 72 | S->vectorDimension = vectorDimension; 73 | S->intercept = intercept; 74 | S->dualCoefficients = dualCoefficients; 75 | S->supportVectors = supportVectors; 76 | S->classes = classes; 77 | } 78 | 79 | 80 | 81 | /** 82 | * @} end of groupSVM group 83 | */ 84 | 85 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 86 | -------------------------------------------------------------------------------- /src/edgeimpulse/edge-impulse-sdk/CMSIS/DSP/Source/FilteringFunctions/arm_iir_lattice_init_q15.c: -------------------------------------------------------------------------------- 1 | #include "edge-impulse-sdk/dsp/config.hpp" 2 | #if EIDSP_LOAD_CMSIS_DSP_SOURCES 3 | /* ---------------------------------------------------------------------- 4 | * Project: CMSIS DSP Library 5 | * Title: arm_iir_lattice_init_q15.c 6 | * Description: Q15 IIR lattice filter initialization function 7 | * 8 | * $Date: 18. March 2019 9 | * $Revision: V1.6.0 10 | * 11 | * Target Processor: Cortex-M cores 12 | * -------------------------------------------------------------------- */ 13 | /* 14 | * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. 15 | * 16 | * SPDX-License-Identifier: Apache-2.0 17 | * 18 | * Licensed under the Apache License, Version 2.0 (the License); you may 19 | * not use this file except in compliance with the License. 20 | * You may obtain a copy of the License at 21 | * 22 | * www.apache.org/licenses/LICENSE-2.0 23 | * 24 | * Unless required by applicable law or agreed to in writing, software 25 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 26 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 27 | * See the License for the specific language governing permissions and 28 | * limitations under the License. 29 | */ 30 | 31 | #include "edge-impulse-sdk/CMSIS/DSP/Include/arm_math.h" 32 | 33 | /** 34 | @ingroup groupFilters 35 | */ 36 | 37 | /** 38 | @addtogroup IIR_Lattice 39 | @{ 40 | */ 41 | 42 | /** 43 | @brief Initialization function for the Q15 IIR lattice filter. 44 | @param[in] S points to an instance of the Q15 IIR lattice structure 45 | @param[in] numStages number of stages in the filter 46 | @param[in] pkCoeffs points to reflection coefficient buffer. The array is of length numStages 47 | @param[in] pvCoeffs points to ladder coefficient buffer. The array is of length numStages+1 48 | @param[in] pState points to state buffer. The array is of length numStages+blockSize 49 | @param[in] blockSize number of samples to process 50 | @return none 51 | */ 52 | 53 | void arm_iir_lattice_init_q15( 54 | arm_iir_lattice_instance_q15 * S, 55 | uint16_t numStages, 56 | q15_t * pkCoeffs, 57 | q15_t * pvCoeffs, 58 | q15_t * pState, 59 | uint32_t blockSize) 60 | { 61 | /* Assign filter taps */ 62 | S->numStages = numStages; 63 | 64 | /* Assign reflection coefficient pointer */ 65 | S->pkCoeffs = pkCoeffs; 66 | 67 | /* Assign ladder coefficient pointer */ 68 | S->pvCoeffs = pvCoeffs; 69 | 70 | /* Clear state buffer and size is always blockSize + numStages */ 71 | memset(pState, 0, (numStages + blockSize) * sizeof(q15_t)); 72 | 73 | /* Assign state pointer */ 74 | S->pState = pState; 75 | } 76 | 77 | /** 78 | @} end of IIR_Lattice group 79 | */ 80 | 81 | #endif // EIDSP_LOAD_CMSIS_DSP_SOURCES 82 | --------------------------------------------------------------------------------