mlonmcu 0.3.0.dev0__3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mlonmcu/__init__.py +26 -0
- mlonmcu/artifact.py +172 -0
- mlonmcu/cli/__init__.py +19 -0
- mlonmcu/cli/build.py +119 -0
- mlonmcu/cli/cleanup.py +75 -0
- mlonmcu/cli/common.py +227 -0
- mlonmcu/cli/compile.py +87 -0
- mlonmcu/cli/env.py +68 -0
- mlonmcu/cli/export.py +93 -0
- mlonmcu/cli/flow.py +67 -0
- mlonmcu/cli/helper/__init__.py +18 -0
- mlonmcu/cli/helper/filter.py +25 -0
- mlonmcu/cli/helper/parse.py +159 -0
- mlonmcu/cli/init.py +130 -0
- mlonmcu/cli/load.py +87 -0
- mlonmcu/cli/main.py +116 -0
- mlonmcu/cli/models.py +48 -0
- mlonmcu/cli/run.py +56 -0
- mlonmcu/cli/setup.py +136 -0
- mlonmcu/cli/tune.py +48 -0
- mlonmcu/config.py +219 -0
- mlonmcu/context/__init__.py +22 -0
- mlonmcu/context/context.py +545 -0
- mlonmcu/context/read_write_filelock.py +327 -0
- mlonmcu/environment/__init__.py +18 -0
- mlonmcu/environment/config.py +214 -0
- mlonmcu/environment/environment.py +501 -0
- mlonmcu/environment/init.py +191 -0
- mlonmcu/environment/list.py +81 -0
- mlonmcu/environment/loader.py +250 -0
- mlonmcu/environment/templates.py +69 -0
- mlonmcu/environment/writer.py +117 -0
- mlonmcu/feature/__init__.py +18 -0
- mlonmcu/feature/feature.py +230 -0
- mlonmcu/feature/features.py +1537 -0
- mlonmcu/feature/type.py +33 -0
- mlonmcu/flow/__init__.py +61 -0
- mlonmcu/flow/backend.py +234 -0
- mlonmcu/flow/framework.py +69 -0
- mlonmcu/flow/tflm/__init__.py +23 -0
- mlonmcu/flow/tflm/backend/__init__.py +23 -0
- mlonmcu/flow/tflm/backend/backend.py +47 -0
- mlonmcu/flow/tflm/backend/tflmc.py +129 -0
- mlonmcu/flow/tflm/backend/tflmi.py +385 -0
- mlonmcu/flow/tflm/framework.py +81 -0
- mlonmcu/flow/tvm/__init__.py +23 -0
- mlonmcu/flow/tvm/backend/__init__.py +26 -0
- mlonmcu/flow/tvm/backend/backend.py +282 -0
- mlonmcu/flow/tvm/backend/model_info.py +307 -0
- mlonmcu/flow/tvm/backend/python_utils.py +36 -0
- mlonmcu/flow/tvm/backend/tuner.py +41 -0
- mlonmcu/flow/tvm/backend/tvmaot.py +162 -0
- mlonmcu/flow/tvm/backend/tvmaotplus.py +51 -0
- mlonmcu/flow/tvm/backend/tvmc_utils.py +172 -0
- mlonmcu/flow/tvm/backend/tvmcg.py +102 -0
- mlonmcu/flow/tvm/backend/tvmllvm.py +106 -0
- mlonmcu/flow/tvm/backend/tvmrt.py +151 -0
- mlonmcu/flow/tvm/backend/wrapper.py +645 -0
- mlonmcu/flow/tvm/framework.py +96 -0
- mlonmcu/logging.py +79 -0
- mlonmcu/mlonmcu.py +19 -0
- mlonmcu/models/__init__.py +31 -0
- mlonmcu/models/convert_data.py +107 -0
- mlonmcu/models/frontend.py +571 -0
- mlonmcu/models/group.py +29 -0
- mlonmcu/models/lookup.py +345 -0
- mlonmcu/models/metadata.py +133 -0
- mlonmcu/models/model.py +104 -0
- mlonmcu/models/options.py +64 -0
- mlonmcu/models/utils.py +136 -0
- mlonmcu/platform/__init__.py +27 -0
- mlonmcu/platform/_platform.py +46 -0
- mlonmcu/platform/espidf/__init__.py +25 -0
- mlonmcu/platform/espidf/espidf.py +489 -0
- mlonmcu/platform/espidf/espidf_target.py +257 -0
- mlonmcu/platform/lookup.py +126 -0
- mlonmcu/platform/microtvm/__init__.py +25 -0
- mlonmcu/platform/microtvm/microtvm.py +580 -0
- mlonmcu/platform/microtvm/microtvm_arduino_target.py +68 -0
- mlonmcu/platform/microtvm/microtvm_backend.py +64 -0
- mlonmcu/platform/microtvm/microtvm_espidf_target.py +94 -0
- mlonmcu/platform/microtvm/microtvm_etissvp_target.py +98 -0
- mlonmcu/platform/microtvm/microtvm_host_target.py +46 -0
- mlonmcu/platform/microtvm/microtvm_spike_target.py +230 -0
- mlonmcu/platform/microtvm/microtvm_target.py +189 -0
- mlonmcu/platform/microtvm/microtvm_template_target.py +55 -0
- mlonmcu/platform/microtvm/microtvm_zephyr_target.py +91 -0
- mlonmcu/platform/mlif/__init__.py +25 -0
- mlonmcu/platform/mlif/mlif.py +300 -0
- mlonmcu/platform/mlif/mlif_target.py +86 -0
- mlonmcu/platform/platform.py +244 -0
- mlonmcu/platform/tvm/__init__.py +25 -0
- mlonmcu/platform/tvm/tvm.py +429 -0
- mlonmcu/platform/tvm/tvm_backend.py +57 -0
- mlonmcu/platform/tvm/tvm_target.py +165 -0
- mlonmcu/platform/zephyr/__init__.py +25 -0
- mlonmcu/platform/zephyr/zephyr.py +450 -0
- mlonmcu/platform/zephyr/zephyr_target.py +110 -0
- mlonmcu/plugins.py +26 -0
- mlonmcu/report.py +99 -0
- mlonmcu/session/__init__.py +18 -0
- mlonmcu/session/postprocess/__init__.py +43 -0
- mlonmcu/session/postprocess/postprocess.py +62 -0
- mlonmcu/session/postprocess/postprocesses.py +487 -0
- mlonmcu/session/run.py +1008 -0
- mlonmcu/session/session.py +373 -0
- mlonmcu/setup/__init__.py +18 -0
- mlonmcu/setup/cache.py +147 -0
- mlonmcu/setup/gen_requirements.py +619 -0
- mlonmcu/setup/setup.py +285 -0
- mlonmcu/setup/task.py +380 -0
- mlonmcu/setup/tasks/__init__.py +40 -0
- mlonmcu/setup/tasks/arm_gcc.py +58 -0
- mlonmcu/setup/tasks/cmsisnn.py +151 -0
- mlonmcu/setup/tasks/common.py +36 -0
- mlonmcu/setup/tasks/corstone300.py +64 -0
- mlonmcu/setup/tasks/espidf.py +87 -0
- mlonmcu/setup/tasks/etiss.py +147 -0
- mlonmcu/setup/tasks/llvm.py +67 -0
- mlonmcu/setup/tasks/mlif.py +49 -0
- mlonmcu/setup/tasks/muriscvnn.py +166 -0
- mlonmcu/setup/tasks/pulp.py +192 -0
- mlonmcu/setup/tasks/riscv_gcc.py +146 -0
- mlonmcu/setup/tasks/spike.py +190 -0
- mlonmcu/setup/tasks/tf.py +92 -0
- mlonmcu/setup/tasks/tflite.py +59 -0
- mlonmcu/setup/tasks/tflmc.py +141 -0
- mlonmcu/setup/tasks/tvm.py +172 -0
- mlonmcu/setup/tasks/utvmcg.py +96 -0
- mlonmcu/setup/tasks/zephyr.py +119 -0
- mlonmcu/setup/utils.py +374 -0
- mlonmcu/target/__init__.py +37 -0
- mlonmcu/target/_target.py +41 -0
- mlonmcu/target/arm/__init__.py +3 -0
- mlonmcu/target/arm/corstone300.py +235 -0
- mlonmcu/target/arm/util.py +109 -0
- mlonmcu/target/common.py +194 -0
- mlonmcu/target/elf.py +256 -0
- mlonmcu/target/host_x86.py +84 -0
- mlonmcu/target/metrics.py +75 -0
- mlonmcu/target/riscv/__init__.py +7 -0
- mlonmcu/target/riscv/etiss_pulpino.py +462 -0
- mlonmcu/target/riscv/gvsoc_pulp.py +215 -0
- mlonmcu/target/riscv/ovpsim.py +301 -0
- mlonmcu/target/riscv/riscv.py +185 -0
- mlonmcu/target/riscv/riscv_qemu.py +166 -0
- mlonmcu/target/riscv/spike.py +243 -0
- mlonmcu/target/riscv/util.py +134 -0
- mlonmcu/target/target.py +200 -0
- mlonmcu/utils.py +49 -0
- mlonmcu/version.py +21 -0
- mlonmcu-0.3.0.dev0.dist-info/LICENSE +202 -0
- mlonmcu-0.3.0.dev0.dist-info/METADATA +343 -0
- mlonmcu-0.3.0.dev0.dist-info/NOTICE +8 -0
- mlonmcu-0.3.0.dev0.dist-info/RECORD +376 -0
- mlonmcu-0.3.0.dev0.dist-info/WHEEL +5 -0
- mlonmcu-0.3.0.dev0.dist-info/entry_points.txt +3 -0
- mlonmcu-0.3.0.dev0.dist-info/top_level.txt +1 -0
- resources/frameworks/tvm/crt_config/README.md +7 -0
- resources/frameworks/tvm/crt_config/crt_config.h +53 -0
- resources/frameworks/tvm/tuning_records/riscv_cpu_v0.01.log.best +46 -0
- resources/patches/fix_esp32c3_march.patch +20 -0
- resources/patches/pulp_freertos_support.patch +55 -0
- resources/platforms/espidf/micro_speech_esp32devboard/CMakeLists.txt +29 -0
- resources/platforms/espidf/micro_speech_esp32devboard/README.md +70 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/CMakeLists.txt +78 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/Kconfig +76 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/default_data.c +26 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/default_model_support/process_input.c +35 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/default_model_support/process_output.c +45 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/include/exit.h +26 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/include/ml_interface.h +70 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/include/printing.h +31 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/ml_interface.c +74 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/ml_interface_tflm.cc +64 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/mlif2/ml_interface_tvm.c +53 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/tflite-lib/CMakeLists.txt +140 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/tflite-lib/Kconfig +8 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/tvm-lib/CMakeLists.txt +66 -0
- resources/platforms/espidf/micro_speech_esp32devboard/components/tvm-lib/Kconfig +7 -0
- resources/platforms/espidf/micro_speech_esp32devboard/example_test.py +38 -0
- resources/platforms/espidf/micro_speech_esp32devboard/info.txt +9 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/CMakeLists.txt +58 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/audio_provider.cc +193 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/audio_provider.h +49 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/command_responder.cc +53 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/command_responder.h +35 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/feature_provider.cc +132 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/feature_provider.cc.orig +145 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/feature_provider.h +55 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/COPYING +11 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/_kiss_fft_guts.h +168 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/kiss_fft.c +408 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/kiss_fft.h +124 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/tools/kiss_fftr.c +159 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/kissfft/tools/kiss_fftr.h +46 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/main.cc +63 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/main_functions.cc +204 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/main_functions.h +37 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/micro_features_generator.cc +121 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/micro_features_generator.h +38 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/micro_model_settings.cc +23 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/micro_model_settings.h +43 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/bits.h +102 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft.cc +52 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft.h +50 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft_util.cc +69 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/fft_util.h +34 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank.c +134 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank.h +63 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank_util.c +220 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/filterbank_util.h +50 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend.c +72 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend.h +64 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend_util.c +85 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/frontend_util.h +52 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/kiss_fft_common.h +48 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/kiss_fft_int16.cc +8 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/kiss_fft_int16.h +34 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_lut.c +30 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_lut.h +40 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale.c +83 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale.h +39 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale_util.c +27 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/log_scale_util.h +45 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction.c +51 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction.h +46 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction_util.c +45 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/noise_reduction_util.h +50 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control.c +56 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control.h +47 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control_util.c +92 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/pcan_gain_control_util.h +57 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window.c +70 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window.h +49 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window_util.c +73 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/microfrontend/lib/window_util.h +45 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/pins.c +14 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/pins.h +30 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/recognize_commands.cc +150 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/recognize_commands.h +173 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/ringbuf.c +333 -0
- resources/platforms/espidf/micro_speech_esp32devboard/main/ringbuf.h +74 -0
- resources/platforms/espidf/micro_speech_esp32devboard/sdkconfig.defaults +36 -0
- resources/platforms/espidf/project/CMakeLists.txt +29 -0
- resources/platforms/espidf/project/README.md +70 -0
- resources/platforms/espidf/project/components/mlif/CMakeLists.txt +77 -0
- resources/platforms/espidf/project/components/mlif/Kconfig +76 -0
- resources/platforms/espidf/project/components/mlif/default_data.c +26 -0
- resources/platforms/espidf/project/components/mlif/default_model_support/process_input.c +35 -0
- resources/platforms/espidf/project/components/mlif/default_model_support/process_output.c +45 -0
- resources/platforms/espidf/project/components/mlif/include/exit.h +26 -0
- resources/platforms/espidf/project/components/mlif/include/ml_interface.h +60 -0
- resources/platforms/espidf/project/components/mlif/include/printing.h +31 -0
- resources/platforms/espidf/project/components/mlif/ml_interface.c +54 -0
- resources/platforms/espidf/project/components/mlif/ml_interface_tflm.cc +40 -0
- resources/platforms/espidf/project/components/mlif/ml_interface_tvm.c +40 -0
- resources/platforms/espidf/project/components/tflite-lib/CMakeLists.txt +142 -0
- resources/platforms/espidf/project/components/tflite-lib/Kconfig +8 -0
- resources/platforms/espidf/project/components/tvm-lib/CMakeLists.txt +66 -0
- resources/platforms/espidf/project/components/tvm-lib/Kconfig +7 -0
- resources/platforms/espidf/project/example_test.py +38 -0
- resources/platforms/espidf/project/main/CMakeLists.txt +25 -0
- resources/platforms/espidf/project/main/main.c +57 -0
- resources/platforms/espidf/project/sdkconfig.defaults +26 -0
- resources/platforms/zephyr/project/CMakeLists.txt +22 -0
- resources/platforms/zephyr/project/Kconfig +101 -0
- resources/platforms/zephyr/project/README.rst +33 -0
- resources/platforms/zephyr/project/cmake/AddAllSubdirs.cmake +21 -0
- resources/platforms/zephyr/project/cmake/ChooseTarget.cmake +22 -0
- resources/platforms/zephyr/project/cmake/LinkTFLite.cmake +223 -0
- resources/platforms/zephyr/project/cmake/LinkTVM.cmake +68 -0
- resources/platforms/zephyr/project/cmake/LookupClang.cmake +41 -0
- resources/platforms/zephyr/project/cmake/backends/tflmc.cmake +5 -0
- resources/platforms/zephyr/project/cmake/backends/tflmi.cmake +5 -0
- resources/platforms/zephyr/project/cmake/backends/tvmaot.cmake +10 -0
- resources/platforms/zephyr/project/cmake/backends/tvmaotplus.cmake +10 -0
- resources/platforms/zephyr/project/cmake/backends/tvmcg.cmake +10 -0
- resources/platforms/zephyr/project/cmake/backends/tvmllvm.cmake +8 -0
- resources/platforms/zephyr/project/cmake/backends/tvmrt.cmake +8 -0
- resources/platforms/zephyr/project/cmake/extras.cmake +9 -0
- resources/platforms/zephyr/project/cmake/features/auto_vectorize_gcc.cmake +65 -0
- resources/platforms/zephyr/project/cmake/features/auto_vectorize_llvm.cmake +20 -0
- resources/platforms/zephyr/project/cmake/features/cmsisnn.cmake +86 -0
- resources/platforms/zephyr/project/cmake/features/muriscvnn.cmake +87 -0
- resources/platforms/zephyr/project/cmake/frameworks/tflm.cmake +1 -0
- resources/platforms/zephyr/project/cmake/frameworks/tflm_mlif.cmake +8 -0
- resources/platforms/zephyr/project/cmake/frameworks/tvm.cmake +1 -0
- resources/platforms/zephyr/project/cmake/frameworks/tvm_mlif.cmake +37 -0
- resources/platforms/zephyr/project/lib/CMakeLists.txt +13 -0
- resources/platforms/zephyr/project/lib/drivers/fake_input.c +10 -0
- resources/platforms/zephyr/project/lib/drivers/fake_input.h +8 -0
- resources/platforms/zephyr/project/lib/ml_interface/CMakeLists.txt +31 -0
- resources/platforms/zephyr/project/lib/ml_interface/default_data.c +8 -0
- resources/platforms/zephyr/project/lib/ml_interface/default_model_support/CMakeLists.txt +2 -0
- resources/platforms/zephyr/project/lib/ml_interface/default_model_support/process_input.c +17 -0
- resources/platforms/zephyr/project/lib/ml_interface/default_model_support/process_output.c +27 -0
- resources/platforms/zephyr/project/lib/ml_interface/ml_interface.c +36 -0
- resources/platforms/zephyr/project/lib/ml_interface/ml_interface.h +47 -0
- resources/platforms/zephyr/project/lib/ml_interface/ml_interface_tflm.cc +22 -0
- resources/platforms/zephyr/project/lib/ml_interface/ml_interface_tvm.c +22 -0
- resources/platforms/zephyr/project/lib/support/CMakeLists.txt +2 -0
- resources/platforms/zephyr/project/lib/support/dummy.c +0 -0
- resources/platforms/zephyr/project/lib/support/exit.h +8 -0
- resources/platforms/zephyr/project/lib/support/printing.h +11 -0
- resources/platforms/zephyr/project/lib/support/quantize.h +23 -0
- resources/platforms/zephyr/project/lib/targets/corstone300.c +62 -0
- resources/platforms/zephyr/project/lib/targets/default.c +2 -0
- resources/platforms/zephyr/project/lib/targets/etiss_pulpino.c +112 -0
- resources/platforms/zephyr/project/lib/targets/generic_riscv.c +112 -0
- resources/platforms/zephyr/project/lib/targets/riscv_qemu.c +112 -0
- resources/platforms/zephyr/project/lib/targets/target.h +2 -0
- resources/platforms/zephyr/project/prj.conf +11 -0
- resources/platforms/zephyr/project/sample.yaml +19 -0
- resources/platforms/zephyr/project/src/main.c +71 -0
- resources/platforms/zephyr/project2/CMakeLists.txt +72 -0
- resources/platforms/zephyr/project2/Kconfig +101 -0
- resources/platforms/zephyr/project2/README.rst +33 -0
- resources/platforms/zephyr/project2/cmake/AddAllSubdirs.cmake +21 -0
- resources/platforms/zephyr/project2/cmake/ChooseTarget.cmake +22 -0
- resources/platforms/zephyr/project2/cmake/LinkTFLite.cmake +223 -0
- resources/platforms/zephyr/project2/cmake/LinkTVM.cmake +68 -0
- resources/platforms/zephyr/project2/cmake/LookupClang.cmake +41 -0
- resources/platforms/zephyr/project2/cmake/backends/tflmc.cmake +5 -0
- resources/platforms/zephyr/project2/cmake/backends/tflmi.cmake +5 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmaot.cmake +10 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmaotplus.cmake +10 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmcg.cmake +10 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmllvm.cmake +8 -0
- resources/platforms/zephyr/project2/cmake/backends/tvmrt.cmake +8 -0
- resources/platforms/zephyr/project2/cmake/extras.cmake +9 -0
- resources/platforms/zephyr/project2/cmake/features/auto_vectorize_gcc.cmake +65 -0
- resources/platforms/zephyr/project2/cmake/features/auto_vectorize_llvm.cmake +20 -0
- resources/platforms/zephyr/project2/cmake/features/cmsisnn.cmake +86 -0
- resources/platforms/zephyr/project2/cmake/features/muriscvnn.cmake +87 -0
- resources/platforms/zephyr/project2/cmake/frameworks/tflm.cmake +1 -0
- resources/platforms/zephyr/project2/cmake/frameworks/tflm_mlif.cmake +8 -0
- resources/platforms/zephyr/project2/cmake/frameworks/tvm.cmake +1 -0
- resources/platforms/zephyr/project2/cmake/frameworks/tvm_mlif.cmake +37 -0
- resources/platforms/zephyr/project2/default_data.c +8 -0
- resources/platforms/zephyr/project2/default_model_support/CMakeLists.txt +3 -0
- resources/platforms/zephyr/project2/default_model_support/process_input.c +17 -0
- resources/platforms/zephyr/project2/default_model_support/process_output.c +27 -0
- resources/platforms/zephyr/project2/lib/CMakeLists.txt +13 -0
- resources/platforms/zephyr/project2/lib/drivers/fake_input.c +10 -0
- resources/platforms/zephyr/project2/lib/drivers/fake_input.h +8 -0
- resources/platforms/zephyr/project2/lib/support/CMakeLists.txt +2 -0
- resources/platforms/zephyr/project2/lib/support/dummy.c +0 -0
- resources/platforms/zephyr/project2/lib/support/exit.h +8 -0
- resources/platforms/zephyr/project2/lib/support/printing.h +11 -0
- resources/platforms/zephyr/project2/lib/support/quantize.h +23 -0
- resources/platforms/zephyr/project2/lib/targets/corstone300.c +62 -0
- resources/platforms/zephyr/project2/lib/targets/default.c +2 -0
- resources/platforms/zephyr/project2/lib/targets/etiss_pulpino.c +112 -0
- resources/platforms/zephyr/project2/lib/targets/generic_riscv.c +112 -0
- resources/platforms/zephyr/project2/lib/targets/riscv_qemu.c +112 -0
- resources/platforms/zephyr/project2/lib/targets/target.h +2 -0
- resources/platforms/zephyr/project2/ml_interface.c +36 -0
- resources/platforms/zephyr/project2/ml_interface.h +47 -0
- resources/platforms/zephyr/project2/ml_interface_tflm.cc +22 -0
- resources/platforms/zephyr/project2/ml_interface_tvm.c +22 -0
- resources/platforms/zephyr/project2/prj.conf +13 -0
- resources/platforms/zephyr/project2/sample.yaml +19 -0
- resources/platforms/zephyr/project2/settings.json +6 -0
- resources/platforms/zephyr/project2/src/main.c +35 -0
- resources/pycharm/.run/README.md +73 -0
- resources/pycharm/.run/step1_ init env.run.xml +24 -0
- resources/pycharm/.run/step2_ setup.run.xml +25 -0
- resources/pycharm/.run/step3_ run resnet on pulpxpulpissimo.run.xml +25 -0
- resources/templates/default.yml.j2 +258 -0
- resources/templates/dev.yml.j2 +212 -0
- resources/templates/minimal.yml.j2 +234 -0
- resources/templates/phi.yml.j2 +282 -0
- resources/templates/pulp.yml.j2 +267 -0
- resources/templates/research.yml.j2 +237 -0
- resources/templates/tumeda.yml.j2 +239 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#ifndef KISS_FTR_H
|
|
2
|
+
#define KISS_FTR_H
|
|
3
|
+
|
|
4
|
+
#include "kiss_fft.h"
|
|
5
|
+
#ifdef __cplusplus
|
|
6
|
+
extern "C" {
|
|
7
|
+
#endif
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
|
|
12
|
+
Real optimized version can save about 45% cpu time vs. complex fft of a real seq.
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
typedef struct kiss_fftr_state *kiss_fftr_cfg;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem);
|
|
22
|
+
/*
|
|
23
|
+
nfft must be even
|
|
24
|
+
|
|
25
|
+
If you don't care to allocate space, use mem = lenmem = NULL
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
void kiss_fftr(kiss_fftr_cfg cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata);
|
|
30
|
+
/*
|
|
31
|
+
input timedata has nfft scalar points
|
|
32
|
+
output freqdata has nfft/2+1 complex points
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
void kiss_fftri(kiss_fftr_cfg cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata);
|
|
36
|
+
/*
|
|
37
|
+
input freqdata has nfft/2+1 complex points
|
|
38
|
+
output timedata has nfft scalar points
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
#define kiss_fftr_free free
|
|
42
|
+
|
|
43
|
+
#ifdef __cplusplus
|
|
44
|
+
}
|
|
45
|
+
#endif
|
|
46
|
+
#endif
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2022 TUM Department of Electrical and Computer Engineering.
|
|
3
|
+
*
|
|
4
|
+
* This file is part of MLonMCU.
|
|
5
|
+
* See https://github.com/tum-ei-eda/mlonmcu.git for further info.
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
#include <stdio.h>
|
|
20
|
+
#include <stdint.h>
|
|
21
|
+
#include "sdkconfig.h"
|
|
22
|
+
#include "freertos/FreeRTOS.h"
|
|
23
|
+
#include "freertos/task.h"
|
|
24
|
+
#include "driver/gpio.h"
|
|
25
|
+
#include "esp_system.h"
|
|
26
|
+
#include "esp_timer.h"
|
|
27
|
+
// #include "esp_private/esp_clk.h"
|
|
28
|
+
// #include "esp_spi_flash.h"
|
|
29
|
+
#include "pins.h"
|
|
30
|
+
|
|
31
|
+
#include "ml_interface.h"
|
|
32
|
+
#include "main_functions.h"
|
|
33
|
+
|
|
34
|
+
extern "C" void app_main(void)
|
|
35
|
+
{
|
|
36
|
+
printf("MLonMCU: START\n");
|
|
37
|
+
gpio_init();
|
|
38
|
+
uint64_t us_before = esp_timer_get_time();
|
|
39
|
+
esp_cpu_ccount_t cc_before = esp_cpu_get_ccount();
|
|
40
|
+
//mlif_run();
|
|
41
|
+
setup();
|
|
42
|
+
while (true) {
|
|
43
|
+
loop();
|
|
44
|
+
}
|
|
45
|
+
uint64_t us_after = esp_timer_get_time();
|
|
46
|
+
uint64_t us_diff = us_after - us_before;
|
|
47
|
+
esp_cpu_ccount_t cc_after = esp_cpu_get_ccount();
|
|
48
|
+
// Warning:
|
|
49
|
+
// 32 bit printf only for newlib nano...
|
|
50
|
+
printf("Total Time: %u us\n", (uint32_t)us_diff);
|
|
51
|
+
printf("Total Cycles: %u\n", (uint32_t)(cc_after - cc_before)); // TODO: overflow possible?
|
|
52
|
+
printf("MLonMCU: STOP\n");
|
|
53
|
+
// printf("Minimum free heap size: %d bytes\n", esp_get_minimum_free_heap_size());
|
|
54
|
+
fflush(stdout);
|
|
55
|
+
|
|
56
|
+
for (int i = 10; i >= 0; i--) {
|
|
57
|
+
printf("Restarting in %d seconds...\n", i);
|
|
58
|
+
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
59
|
+
}
|
|
60
|
+
printf("Restarting now.\n");
|
|
61
|
+
fflush(stdout);
|
|
62
|
+
esp_restart();
|
|
63
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
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 "main_functions.h"
|
|
17
|
+
|
|
18
|
+
#include "freertos/FreeRTOS.h"
|
|
19
|
+
#include "freertos/task.h"
|
|
20
|
+
#include "audio_provider.h"
|
|
21
|
+
#include "command_responder.h"
|
|
22
|
+
#include "feature_provider.h"
|
|
23
|
+
#include "micro_model_settings.h"
|
|
24
|
+
#include "recognize_commands.h"
|
|
25
|
+
#include "ml_interface.h"
|
|
26
|
+
|
|
27
|
+
// #include "tvm_wrapper.h"
|
|
28
|
+
// #include "tensorflow/lite/micro/micro_error_reporter.h"
|
|
29
|
+
// #include "tensorflow/lite/micro/micro_interpreter.h"
|
|
30
|
+
// #include "tensorflow/lite/micro/micro_mutable_op_resolver.h"
|
|
31
|
+
// #include "tensorflow/lite/micro/system_setup.h"
|
|
32
|
+
// #include "tensorflow/lite/schema/schema_generated.h"
|
|
33
|
+
|
|
34
|
+
// Globals, used for compatibility with Arduino-style sketches.
|
|
35
|
+
namespace {
|
|
36
|
+
// tflite::ErrorReporter* error_reporter = nullptr;
|
|
37
|
+
// const tflite::Model* model = nullptr;
|
|
38
|
+
// tflite::MicroInterpreter* interpreter = nullptr;
|
|
39
|
+
// TfLiteTensor* model_input = nullptr;
|
|
40
|
+
FeatureProvider* feature_provider = nullptr;
|
|
41
|
+
RecognizeCommands* recognizer = nullptr;
|
|
42
|
+
int32_t previous_time = 0;
|
|
43
|
+
|
|
44
|
+
// Create an area of memory to use for input, output, and intermediate arrays.
|
|
45
|
+
// The size of this will depend on the model you're using, and may need to be
|
|
46
|
+
// determined by experimentation.
|
|
47
|
+
// constexpr int kTensorArenaSize = 30 * 1024;
|
|
48
|
+
// uint8_t tensor_arena[kTensorArenaSize];
|
|
49
|
+
int8_t feature_buffer[kFeatureElementCount];
|
|
50
|
+
int8_t* model_input_buffer = nullptr;
|
|
51
|
+
} // namespace
|
|
52
|
+
|
|
53
|
+
// The name of this function is important for Arduino compatibility.
|
|
54
|
+
void setup() {
|
|
55
|
+
mlif_init();
|
|
56
|
+
// Set up logging. Google style is to avoid globals or statics because of
|
|
57
|
+
// lifetime uncertainty, but since this has a trivial destructor it's okay.
|
|
58
|
+
// NOLINTNEXTLINE(runtime-global-variables)
|
|
59
|
+
// static tflite::MicroErrorReporter micro_error_reporter;
|
|
60
|
+
// error_reporter = µ_error_reporter;
|
|
61
|
+
|
|
62
|
+
// // Map the model into a usable data structure. This doesn't involve any
|
|
63
|
+
// // copying or parsing, it's a very lightweight operation.
|
|
64
|
+
// model = tflite::GetModel(g_model);
|
|
65
|
+
// if (model->version() != TFLITE_SCHEMA_VERSION) {
|
|
66
|
+
// TF_LITE_REPORT_ERROR(error_reporter,
|
|
67
|
+
// "Model provided is schema version %d not equal "
|
|
68
|
+
// "to supported version %d.",
|
|
69
|
+
// model->version(), TFLITE_SCHEMA_VERSION);
|
|
70
|
+
// return;
|
|
71
|
+
// }
|
|
72
|
+
|
|
73
|
+
// // Pull in only the operation implementations we need.
|
|
74
|
+
// // This relies on a complete list of all the ops needed by this graph.
|
|
75
|
+
// // An easier approach is to just use the AllOpsResolver, but this will
|
|
76
|
+
// // incur some penalty in code space for op implementations that are not
|
|
77
|
+
// // needed by this graph.
|
|
78
|
+
// //
|
|
79
|
+
// // tflite::AllOpsResolver resolver;
|
|
80
|
+
// // NOLINTNEXTLINE(runtime-global-variables)
|
|
81
|
+
// static tflite::MicroMutableOpResolver<4> micro_op_resolver(error_reporter);
|
|
82
|
+
// if (micro_op_resolver.AddDepthwiseConv2D() != kTfLiteOk) {
|
|
83
|
+
// return;
|
|
84
|
+
// }
|
|
85
|
+
// if (micro_op_resolver.AddFullyConnected() != kTfLiteOk) {
|
|
86
|
+
// return;
|
|
87
|
+
// }
|
|
88
|
+
// if (micro_op_resolver.AddSoftmax() != kTfLiteOk) {
|
|
89
|
+
// return;
|
|
90
|
+
// }
|
|
91
|
+
// if (micro_op_resolver.AddReshape() != kTfLiteOk) {
|
|
92
|
+
// return;
|
|
93
|
+
// }
|
|
94
|
+
|
|
95
|
+
// // Build an interpreter to run the model with.
|
|
96
|
+
// static tflite::MicroInterpreter static_interpreter(
|
|
97
|
+
// model, micro_op_resolver, tensor_arena, kTensorArenaSize, error_reporter);
|
|
98
|
+
// interpreter = &static_interpreter;
|
|
99
|
+
|
|
100
|
+
// // Allocate memory from the tensor_arena for the model's tensors.
|
|
101
|
+
// TfLiteStatus allocate_status = interpreter->AllocateTensors();
|
|
102
|
+
// if (allocate_status != kTfLiteOk) {
|
|
103
|
+
// TF_LITE_REPORT_ERROR(error_reporter, "AllocateTensors() failed");
|
|
104
|
+
// return;
|
|
105
|
+
// }
|
|
106
|
+
|
|
107
|
+
// // Get information about the memory area to use for the model's input.
|
|
108
|
+
// model_input = interpreter->input(0);
|
|
109
|
+
// if ((model_input->dims->size != 2) || (model_input->dims->data[0] != 1) ||
|
|
110
|
+
// (model_input->dims->data[1] !=
|
|
111
|
+
// (kFeatureSliceCount * kFeatureSliceSize)) ||
|
|
112
|
+
// (model_input->type != kTfLiteInt8)) {
|
|
113
|
+
// TF_LITE_REPORT_ERROR(error_reporter,
|
|
114
|
+
// "Bad input tensor parameters in model");
|
|
115
|
+
// return;
|
|
116
|
+
// }
|
|
117
|
+
// model_input_buffer = model_input->data.int8;
|
|
118
|
+
model_input_buffer = (int8_t*)mlif_input_ptr(0);
|
|
119
|
+
|
|
120
|
+
// Prepare to access the audio spectrograms from a microphone or other source
|
|
121
|
+
// that will provide the inputs to the neural network.
|
|
122
|
+
// NOLINTNEXTLINE(runtime-global-variables)
|
|
123
|
+
static FeatureProvider static_feature_provider(kFeatureElementCount,
|
|
124
|
+
feature_buffer);
|
|
125
|
+
feature_provider = &static_feature_provider;
|
|
126
|
+
|
|
127
|
+
// static RecognizeCommands static_recognizer(error_reporter);
|
|
128
|
+
static RecognizeCommands static_recognizer;
|
|
129
|
+
recognizer = &static_recognizer;
|
|
130
|
+
|
|
131
|
+
previous_time = 0;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// The name of this function is important for Arduino compatibility.
|
|
135
|
+
void loop() {
|
|
136
|
+
// Fetch the spectrogram for the current time.
|
|
137
|
+
uint32_t start1 = xTaskGetTickCount();
|
|
138
|
+
const int32_t current_time = LatestAudioTimestamp();
|
|
139
|
+
int how_many_new_slices = 0;
|
|
140
|
+
// TfLiteStatus feature_status = feature_provider->PopulateFeatureData(
|
|
141
|
+
// error_reporter, previous_time, current_time, &how_many_new_slices);
|
|
142
|
+
int feature_status = feature_provider->PopulateFeatureData(
|
|
143
|
+
previous_time, current_time, &how_many_new_slices);
|
|
144
|
+
// printf("how_many_new_slices=%d\n", how_many_new_slices);
|
|
145
|
+
if (feature_status != 0) {
|
|
146
|
+
// TF_LITE_REPORT_ERROR(error_reporter, "Feature generation failed");
|
|
147
|
+
printf("Feature generation failed\n");
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
// printf("current_time=%ld\n", current_time);
|
|
151
|
+
previous_time = current_time;
|
|
152
|
+
// If no new audio samples have been received since last time, don't bother
|
|
153
|
+
// running the network model.
|
|
154
|
+
if (how_many_new_slices == 0) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
uint32_t end1 = xTaskGetTickCount();
|
|
158
|
+
// printf("ticks1=%lu\n", end1-start1);
|
|
159
|
+
|
|
160
|
+
// Copy feature buffer to input tensor
|
|
161
|
+
for (int i = 0; i < kFeatureElementCount; i++) {
|
|
162
|
+
model_input_buffer[i] = feature_buffer[i];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Run the model on the spectrogram input and make sure it succeeds.
|
|
166
|
+
// TfLiteStatus invoke_status = interpreter->Invoke();
|
|
167
|
+
// if (invoke_status != kTfLiteOk) {
|
|
168
|
+
// TF_LITE_REPORT_ERROR(error_reporter, "Invoke failed");
|
|
169
|
+
// return;
|
|
170
|
+
// }
|
|
171
|
+
uint32_t start2 = xTaskGetTickCount();
|
|
172
|
+
mlif_invoke();
|
|
173
|
+
uint32_t end2 = xTaskGetTickCount();
|
|
174
|
+
// printf("ticks2=%lu\n", end2-start2);
|
|
175
|
+
|
|
176
|
+
// Obtain a pointer to the output tensor
|
|
177
|
+
// TfLiteTensor* output = interpreter->output(0);
|
|
178
|
+
int8_t* output_ptr = (int8_t*)mlif_output_ptr(0);
|
|
179
|
+
printf("%4d, \t%d, \t%4d, \t%4d\n", output_ptr[0]+128, output_ptr[1]+128, output_ptr[2]+128, output_ptr[3]+128);
|
|
180
|
+
// Determine whether a command was recognized based on the output of inference
|
|
181
|
+
const char* found_command = nullptr;
|
|
182
|
+
uint8_t score = 0;
|
|
183
|
+
bool is_new_command = false;
|
|
184
|
+
uint32_t start3 = xTaskGetTickCount();
|
|
185
|
+
// TfLiteStatus process_status = recognizer->ProcessLatestResults(
|
|
186
|
+
// output, current_time, &found_command, &score, &is_new_command);
|
|
187
|
+
int process_status = recognizer->ProcessLatestResults(
|
|
188
|
+
output_ptr, current_time, &found_command, &score, &is_new_command);
|
|
189
|
+
if (process_status != 0) {
|
|
190
|
+
// TF_LITE_REPORT_ERROR(error_reporter,
|
|
191
|
+
// "RecognizeCommands::ProcessLatestResults() failed");
|
|
192
|
+
printf("RecognizeCommands::ProcessLatestResults() failed\n");
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
// Do something based on the recognized command. The default implementation
|
|
196
|
+
// just prints to the error console, but you should replace this with your
|
|
197
|
+
// own function for a real application.
|
|
198
|
+
// RespondToCommand(error_reporter, current_time, found_command, score,
|
|
199
|
+
// is_new_command);
|
|
200
|
+
RespondToCommand(current_time, found_command, score,
|
|
201
|
+
is_new_command);
|
|
202
|
+
uint32_t end3 = xTaskGetTickCount();
|
|
203
|
+
// printf("ticks3=%lu\n", end3-start3);
|
|
204
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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_EXAMPLES_MICRO_SPEECH_MAIN_FUNCTIONS_H_
|
|
17
|
+
#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MAIN_FUNCTIONS_H_
|
|
18
|
+
|
|
19
|
+
// Expose a C friendly interface for main functions.
|
|
20
|
+
#ifdef __cplusplus
|
|
21
|
+
extern "C" {
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
// Initializes all data needed for the example. The name is important, and needs
|
|
25
|
+
// to be setup() for Arduino compatibility.
|
|
26
|
+
void setup();
|
|
27
|
+
|
|
28
|
+
// Runs one iteration of data gathering and inference. This should be called
|
|
29
|
+
// repeatedly from the application code. The name needs to be loop() for Arduino
|
|
30
|
+
// compatibility.
|
|
31
|
+
void loop();
|
|
32
|
+
|
|
33
|
+
#ifdef __cplusplus
|
|
34
|
+
}
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MAIN_FUNCTIONS_H_
|
|
@@ -0,0 +1,121 @@
|
|
|
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 "micro_features_generator.h"
|
|
17
|
+
|
|
18
|
+
#include <cmath>
|
|
19
|
+
#include <stdio.h>
|
|
20
|
+
#include <cstring>
|
|
21
|
+
|
|
22
|
+
#include "microfrontend/lib/frontend.h"
|
|
23
|
+
#include "microfrontend/lib/frontend_util.h"
|
|
24
|
+
#include "micro_model_settings.h"
|
|
25
|
+
|
|
26
|
+
// Configure FFT to output 16 bit fixed point.
|
|
27
|
+
#define FIXED_POINT 16
|
|
28
|
+
|
|
29
|
+
namespace {
|
|
30
|
+
|
|
31
|
+
FrontendState g_micro_features_state;
|
|
32
|
+
bool g_is_first_time = true;
|
|
33
|
+
|
|
34
|
+
} // namespace
|
|
35
|
+
|
|
36
|
+
// TfLiteStatus InitializeMicroFeatures(tflite::ErrorReporter* error_reporter) {
|
|
37
|
+
int InitializeMicroFeatures() {
|
|
38
|
+
FrontendConfig config;
|
|
39
|
+
config.window.size_ms = kFeatureSliceDurationMs;
|
|
40
|
+
config.window.step_size_ms = kFeatureSliceStrideMs;
|
|
41
|
+
config.noise_reduction.smoothing_bits = 10;
|
|
42
|
+
config.filterbank.num_channels = kFeatureSliceSize;
|
|
43
|
+
config.filterbank.lower_band_limit = 125.0;
|
|
44
|
+
config.filterbank.upper_band_limit = 7500.0;
|
|
45
|
+
config.noise_reduction.smoothing_bits = 10;
|
|
46
|
+
config.noise_reduction.even_smoothing = 0.025;
|
|
47
|
+
config.noise_reduction.odd_smoothing = 0.06;
|
|
48
|
+
config.noise_reduction.min_signal_remaining = 0.05;
|
|
49
|
+
config.pcan_gain_control.enable_pcan = 1;
|
|
50
|
+
config.pcan_gain_control.strength = 0.95;
|
|
51
|
+
config.pcan_gain_control.offset = 80.0;
|
|
52
|
+
config.pcan_gain_control.gain_bits = 21;
|
|
53
|
+
config.log_scale.enable_log = 1;
|
|
54
|
+
config.log_scale.scale_shift = 6;
|
|
55
|
+
if (!FrontendPopulateState(&config, &g_micro_features_state,
|
|
56
|
+
kAudioSampleFrequency)) {
|
|
57
|
+
printf("FrontendPopulateState() failed\n");
|
|
58
|
+
return -1;
|
|
59
|
+
}
|
|
60
|
+
g_is_first_time = true;
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// This is not exposed in any header, and is only used for testing, to ensure
|
|
65
|
+
// that the state is correctly set up before generating results.
|
|
66
|
+
void SetMicroFeaturesNoiseEstimates(const uint32_t* estimate_presets) {
|
|
67
|
+
for (int i = 0; i < g_micro_features_state.filterbank.num_channels; ++i) {
|
|
68
|
+
g_micro_features_state.noise_reduction.estimate[i] = estimate_presets[i];
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// TfLiteStatus GenerateMicroFeatures(tflite::ErrorReporter* error_reporter,
|
|
73
|
+
// const int16_t* input, int input_size,
|
|
74
|
+
// int output_size, int8_t* output,
|
|
75
|
+
// size_t* num_samples_read) {
|
|
76
|
+
int GenerateMicroFeatures(const int16_t* input, int input_size,
|
|
77
|
+
int output_size, int8_t* output,
|
|
78
|
+
size_t* num_samples_read) {
|
|
79
|
+
const int16_t* frontend_input;
|
|
80
|
+
if (g_is_first_time) {
|
|
81
|
+
frontend_input = input;
|
|
82
|
+
g_is_first_time = false;
|
|
83
|
+
} else {
|
|
84
|
+
frontend_input = input + 160;
|
|
85
|
+
}
|
|
86
|
+
FrontendOutput frontend_output = FrontendProcessSamples(
|
|
87
|
+
&g_micro_features_state, frontend_input, input_size, num_samples_read);
|
|
88
|
+
|
|
89
|
+
for (size_t i = 0; i < frontend_output.size; ++i) {
|
|
90
|
+
// These scaling values are derived from those used in input_data.py in the
|
|
91
|
+
// training pipeline.
|
|
92
|
+
// The feature pipeline outputs 16-bit signed integers in roughly a 0 to 670
|
|
93
|
+
// range. In training, these are then arbitrarily divided by 25.6 to get
|
|
94
|
+
// float values in the rough range of 0.0 to 26.0. This scaling is performed
|
|
95
|
+
// for historical reasons, to match up with the output of other feature
|
|
96
|
+
// generators.
|
|
97
|
+
// The process is then further complicated when we quantize the model. This
|
|
98
|
+
// means we have to scale the 0.0 to 26.0 real values to the -128 to 127
|
|
99
|
+
// signed integer numbers.
|
|
100
|
+
// All this means that to get matching values from our integer feature
|
|
101
|
+
// output into the tensor input, we have to perform:
|
|
102
|
+
// input = (((feature / 25.6) / 26.0) * 256) - 128
|
|
103
|
+
// To simplify this and perform it in 32-bit integer math, we rearrange to:
|
|
104
|
+
// input = (feature * 256) / (25.6 * 26.0) - 128
|
|
105
|
+
constexpr int32_t value_scale = 256;
|
|
106
|
+
constexpr int32_t value_div = static_cast<int32_t>((25.6f * 26.0f) + 0.5f);
|
|
107
|
+
int32_t value =
|
|
108
|
+
((frontend_output.values[i] * value_scale) + (value_div / 2)) /
|
|
109
|
+
value_div;
|
|
110
|
+
value -= 128;
|
|
111
|
+
if (value < -128) {
|
|
112
|
+
value = -128;
|
|
113
|
+
}
|
|
114
|
+
if (value > 127) {
|
|
115
|
+
value = 127;
|
|
116
|
+
}
|
|
117
|
+
output[i] = value;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_
|
|
17
|
+
#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_
|
|
18
|
+
|
|
19
|
+
#include <stdint.h>
|
|
20
|
+
#include <stddef.h>
|
|
21
|
+
// #include "tensorflow/lite/c/common.h"
|
|
22
|
+
// #include "tensorflow/lite/micro/micro_error_reporter.h"
|
|
23
|
+
|
|
24
|
+
// Sets up any resources needed for the feature generation pipeline.
|
|
25
|
+
// TfLiteStatus InitializeMicroFeatures(tflite::ErrorReporter* error_reporter);
|
|
26
|
+
int InitializeMicroFeatures();
|
|
27
|
+
|
|
28
|
+
// Converts audio sample data into a more compact form that's appropriate for
|
|
29
|
+
// feeding into a neural network.
|
|
30
|
+
// TfLiteStatus GenerateMicroFeatures(tflite::ErrorReporter* error_reporter,
|
|
31
|
+
// const int16_t* input, int input_size,
|
|
32
|
+
// int output_size, int8_t* output,
|
|
33
|
+
// size_t* num_samples_read);
|
|
34
|
+
int GenerateMicroFeatures(const int16_t* input, int input_size,
|
|
35
|
+
int output_size, int8_t* output,
|
|
36
|
+
size_t* num_samples_read);
|
|
37
|
+
|
|
38
|
+
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_FEATURES_GENERATOR_H_
|
|
@@ -0,0 +1,23 @@
|
|
|
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 "micro_model_settings.h"
|
|
17
|
+
|
|
18
|
+
const char* kCategoryLabels[kCategoryCount] = {
|
|
19
|
+
"silence",
|
|
20
|
+
"unknown",
|
|
21
|
+
"up", // TODO: make this variable/generic
|
|
22
|
+
"down",
|
|
23
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
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_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_MODEL_SETTINGS_H_
|
|
17
|
+
#define TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_MODEL_SETTINGS_H_
|
|
18
|
+
|
|
19
|
+
// Keeping these as constant expressions allow us to allocate fixed-sized arrays
|
|
20
|
+
// on the stack for our working memory.
|
|
21
|
+
|
|
22
|
+
// The size of the input time series data we pass to the FFT to produce the
|
|
23
|
+
// frequency information. This has to be a power of two, and since we're dealing
|
|
24
|
+
// with 30ms of 16KHz inputs, which means 480 samples, this is the next value.
|
|
25
|
+
constexpr int kMaxAudioSampleSize = 512;
|
|
26
|
+
constexpr int kAudioSampleFrequency = 16000;
|
|
27
|
+
|
|
28
|
+
// The following values are derived from values used during model training.
|
|
29
|
+
// If you change the way you preprocess the input, update all these constants.
|
|
30
|
+
constexpr int kFeatureSliceSize = 40;
|
|
31
|
+
constexpr int kFeatureSliceCount = 49;
|
|
32
|
+
constexpr int kFeatureElementCount = (kFeatureSliceSize * kFeatureSliceCount);
|
|
33
|
+
constexpr int kFeatureSliceStrideMs = 20;
|
|
34
|
+
constexpr int kFeatureSliceDurationMs = 30;
|
|
35
|
+
|
|
36
|
+
// Variables for the model's output categories.
|
|
37
|
+
constexpr int kSilenceIndex = 0;
|
|
38
|
+
constexpr int kUnknownIndex = 1;
|
|
39
|
+
// If you modify the output categories, you need to update the following values.
|
|
40
|
+
constexpr int kCategoryCount = 4;
|
|
41
|
+
extern const char* kCategoryLabels[kCategoryCount];
|
|
42
|
+
|
|
43
|
+
#endif // TENSORFLOW_LITE_MICRO_EXAMPLES_MICRO_SPEECH_MICRO_FEATURES_MICRO_MODEL_SETTINGS_H_
|
|
@@ -0,0 +1,102 @@
|
|
|
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_EXPERIMENTAL_MICROFRONTEND_LIB_BITS_H_
|
|
16
|
+
#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_BITS_H_
|
|
17
|
+
|
|
18
|
+
#ifdef __cplusplus
|
|
19
|
+
#include <cstdint>
|
|
20
|
+
|
|
21
|
+
extern "C" {
|
|
22
|
+
#endif
|
|
23
|
+
|
|
24
|
+
static inline int CountLeadingZeros32Slow(uint64_t n) {
|
|
25
|
+
int zeroes = 28;
|
|
26
|
+
if (n >> 16) zeroes -= 16, n >>= 16;
|
|
27
|
+
if (n >> 8) zeroes -= 8, n >>= 8;
|
|
28
|
+
if (n >> 4) zeroes -= 4, n >>= 4;
|
|
29
|
+
return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static inline int CountLeadingZeros32(uint32_t n) {
|
|
33
|
+
#if defined(_MSC_VER)
|
|
34
|
+
unsigned long result = 0; // NOLINT(runtime/int)
|
|
35
|
+
if (_BitScanReverse(&result, n)) {
|
|
36
|
+
return 31 - result;
|
|
37
|
+
}
|
|
38
|
+
return 32;
|
|
39
|
+
#elif defined(__GNUC__)
|
|
40
|
+
|
|
41
|
+
// Handle 0 as a special case because __builtin_clz(0) is undefined.
|
|
42
|
+
if (n == 0) {
|
|
43
|
+
return 32;
|
|
44
|
+
}
|
|
45
|
+
return __builtin_clz(n);
|
|
46
|
+
#else
|
|
47
|
+
return CountLeadingZeros32Slow(n);
|
|
48
|
+
#endif
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static inline int MostSignificantBit32(uint32_t n) {
|
|
52
|
+
return 32 - CountLeadingZeros32(n);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static inline int CountLeadingZeros64Slow(uint64_t n) {
|
|
56
|
+
int zeroes = 60;
|
|
57
|
+
if (n >> 32) zeroes -= 32, n >>= 32;
|
|
58
|
+
if (n >> 16) zeroes -= 16, n >>= 16;
|
|
59
|
+
if (n >> 8) zeroes -= 8, n >>= 8;
|
|
60
|
+
if (n >> 4) zeroes -= 4, n >>= 4;
|
|
61
|
+
return "\4\3\2\2\1\1\1\1\0\0\0\0\0\0\0"[n] + zeroes;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static inline int CountLeadingZeros64(uint64_t n) {
|
|
65
|
+
#if defined(_MSC_VER) && defined(_M_X64)
|
|
66
|
+
// MSVC does not have __builtin_clzll. Use _BitScanReverse64.
|
|
67
|
+
unsigned long result = 0; // NOLINT(runtime/int)
|
|
68
|
+
if (_BitScanReverse64(&result, n)) {
|
|
69
|
+
return 63 - result;
|
|
70
|
+
}
|
|
71
|
+
return 64;
|
|
72
|
+
#elif defined(_MSC_VER)
|
|
73
|
+
// MSVC does not have __builtin_clzll. Compose two calls to _BitScanReverse
|
|
74
|
+
unsigned long result = 0; // NOLINT(runtime/int)
|
|
75
|
+
if ((n >> 32) && _BitScanReverse(&result, n >> 32)) {
|
|
76
|
+
return 31 - result;
|
|
77
|
+
}
|
|
78
|
+
if (_BitScanReverse(&result, n)) {
|
|
79
|
+
return 63 - result;
|
|
80
|
+
}
|
|
81
|
+
return 64;
|
|
82
|
+
#elif defined(__GNUC__)
|
|
83
|
+
|
|
84
|
+
// Handle 0 as a special case because __builtin_clzll(0) is undefined.
|
|
85
|
+
if (n == 0) {
|
|
86
|
+
return 64;
|
|
87
|
+
}
|
|
88
|
+
return __builtin_clzll(n);
|
|
89
|
+
#else
|
|
90
|
+
return CountLeadingZeros64Slow(n);
|
|
91
|
+
#endif
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static inline int MostSignificantBit64(uint64_t n) {
|
|
95
|
+
return 64 - CountLeadingZeros64(n);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#ifdef __cplusplus
|
|
99
|
+
} // extern "C"
|
|
100
|
+
#endif
|
|
101
|
+
|
|
102
|
+
#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_BITS_H_
|