diff --git a/tests/pkg_tensorflow-lite/Makefile b/tests/pkg_tensorflow-lite/Makefile deleted file mode 100644 index cdb9b2b7c00c..000000000000 --- a/tests/pkg_tensorflow-lite/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -# Ensure minimal size by default -DEVELHELP ?= 0 - -include ../Makefile.tests_common - -# Other available example: hello_world -EXAMPLE ?= mnist - -USEPKG += tensorflow-lite - -# internal mnist example is available as an external module -ifeq (mnist,$(EXAMPLE)) - # TensorFlow-Lite crashes on M4/M7 CPUs when FPU is enabled, so disable it by - # default for now - DISABLE_MODULE += cortexm_fpu - USEMODULE += $(EXAMPLE) - EXTERNAL_MODULE_DIRS += external_modules -else - # Use upstream example - USEMODULE += tensorflow-lite-$(EXAMPLE) -endif - -include $(RIOTBASE)/Makefile.include diff --git a/tests/pkg_tflite-micro/Makefile b/tests/pkg_tflite-micro/Makefile new file mode 100644 index 000000000000..eec183604c53 --- /dev/null +++ b/tests/pkg_tflite-micro/Makefile @@ -0,0 +1,14 @@ +# Ensure minimal size by default +DEVELHELP ?= 0 + +include ../Makefile.tests_common + +USEPKG += tflite-micro + +# TensorFlow-Lite crashes on M4/M7 CPUs when FPU is enabled, so disable it by +# default for now +DISABLE_MODULE += cortexm_fpu +USEMODULE += mnist +EXTERNAL_MODULE_DIRS += external_modules + +include $(RIOTBASE)/Makefile.include diff --git a/tests/pkg_tensorflow-lite/Makefile.ci b/tests/pkg_tflite-micro/Makefile.ci similarity index 55% rename from tests/pkg_tensorflow-lite/Makefile.ci rename to tests/pkg_tflite-micro/Makefile.ci index 3e3a074832f1..34cb70561716 100644 --- a/tests/pkg_tensorflow-lite/Makefile.ci +++ b/tests/pkg_tflite-micro/Makefile.ci @@ -4,15 +4,37 @@ BOARD_INSUFFICIENT_MEMORY := \ arduino-mkrfox1200 \ arduino-mkrwan1300 \ arduino-mkrzero \ + arduino-nano-33-iot \ + arduino-zero \ b-l072z-lrwan1 \ + bastwan \ blackpill \ + blackpill-128kib \ bluepill \ + bluepill-128kib \ bluepill-stm32f030c8 \ calliope-mini \ + cc1350-launchpad \ + cc2650-launchpad \ + cc2650stk \ + e104-bt5010a-tb \ + e104-bt5011a-tb \ + e180-zg120b-tb \ + esp8266-esp-12x \ + esp8266-olimex-mod \ + esp8266-sparkfun-thing \ feather-m0 \ + feather-m0-lora \ + feather-m0-wifi \ + frdm-kl43z \ frdm-kw41z \ + hamilton \ i-nucleo-lrwan1 \ + ikea-tradfri \ + im880b \ + lobaro-lorabox \ lsn50 \ + maple-mini \ microbit \ nrf51dk \ nrf51dongle \ @@ -23,16 +45,28 @@ BOARD_INSUFFICIENT_MEMORY := \ nucleo-f070rb \ nucleo-f072rb \ nucleo-f091rc \ + nucleo-f103rb \ nucleo-f302r8 \ nucleo-f303k8 \ nucleo-f334r8 \ + nucleo-f410rb \ + nucleo-g070rb \ nucleo-g071rb \ + nucleo-g431kb \ + nucleo-g431rb \ nucleo-l011k4 \ nucleo-l031k6 \ nucleo-l053r8 \ nucleo-l073rz \ + nucleo-l412kb \ + nucleo-wl55jc \ + olimexino-stm32 \ + opencm904 \ + openlabs-kw41z-mini-256kib \ + pba-d-01-kw2x \ phynode-kw41z \ samd10-xmini \ + samd20-xpro \ samd21-xpro \ saml10-xpro \ saml11-xpro \ @@ -40,19 +74,31 @@ BOARD_INSUFFICIENT_MEMORY := \ samr21-xpro \ samr30-xpro \ samr34-xpro \ + seeeduino_xiao \ sensebox_samd21 \ + serpente \ slstk3400a \ + slstk3401a \ + sltb001a \ + slwstk6000b-slwrb4150a \ + slwstk6220a \ sodaq-autonomo \ sodaq-explorer \ sodaq-one \ sodaq-sara-aff \ sodaq-sara-sff \ + spark-core \ stk3200 \ + stk3600 \ stm32f030f4-demo \ stm32f0discovery \ stm32g0316-disco \ stm32l0538-disco \ stm32mp157c-dk2 \ + teensy31 \ usb-kw41z \ + weact-f401cc \ + wemos-zero \ + yarm \ yunjia-nrf51822 \ # diff --git a/tests/pkg_tensorflow-lite/README.md b/tests/pkg_tflite-micro/README.md similarity index 100% rename from tests/pkg_tensorflow-lite/README.md rename to tests/pkg_tflite-micro/README.md diff --git a/tests/pkg_tensorflow-lite/external_modules/mnist/.gitignore b/tests/pkg_tflite-micro/external_modules/mnist/.gitignore similarity index 100% rename from tests/pkg_tensorflow-lite/external_modules/mnist/.gitignore rename to tests/pkg_tflite-micro/external_modules/mnist/.gitignore diff --git a/tests/pkg_tensorflow-lite/external_modules/mnist/Makefile b/tests/pkg_tflite-micro/external_modules/mnist/Makefile similarity index 100% rename from tests/pkg_tensorflow-lite/external_modules/mnist/Makefile rename to tests/pkg_tflite-micro/external_modules/mnist/Makefile diff --git a/tests/pkg_tensorflow-lite/external_modules/mnist/digit b/tests/pkg_tflite-micro/external_modules/mnist/digit similarity index 100% rename from tests/pkg_tensorflow-lite/external_modules/mnist/digit rename to tests/pkg_tflite-micro/external_modules/mnist/digit diff --git a/tests/pkg_tensorflow-lite/external_modules/mnist/generate_digit.py b/tests/pkg_tflite-micro/external_modules/mnist/generate_digit.py similarity index 100% rename from tests/pkg_tensorflow-lite/external_modules/mnist/generate_digit.py rename to tests/pkg_tflite-micro/external_modules/mnist/generate_digit.py diff --git a/tests/pkg_tensorflow-lite/external_modules/mnist/main_functions.cc b/tests/pkg_tflite-micro/external_modules/mnist/main_functions.cc similarity index 79% rename from tests/pkg_tensorflow-lite/external_modules/mnist/main_functions.cc rename to tests/pkg_tflite-micro/external_modules/mnist/main_functions.cc index 6468c3af7bc4..ffd753dae060 100644 --- a/tests/pkg_tensorflow-lite/external_modules/mnist/main_functions.cc +++ b/tests/pkg_tflite-micro/external_modules/mnist/main_functions.cc @@ -16,12 +16,19 @@ */ #include +#include "kernel_defines.h" +#if IS_USED(MODULE_TENSORFLOW_LITE) +#include "tensorflow/lite/micro/kernels/all_ops_resolver.h" #include "tensorflow/lite/micro/micro_error_reporter.h" #include "tensorflow/lite/micro/micro_interpreter.h" -#include "tensorflow/lite/micro/kernels/micro_ops.h" -#include "tensorflow/lite/micro/micro_mutable_op_resolver.h" -#include "tensorflow/lite/schema/schema_generated.h" #include "tensorflow/lite/version.h" +#else +#include "tensorflow/lite/micro/all_ops_resolver.h" +#include "tensorflow/lite/micro/micro_error_reporter.h" +#include "tensorflow/lite/micro/micro_interpreter.h" +#include "tensorflow/lite/micro/system_setup.h" +#endif +#include "tensorflow/lite/schema/schema_generated.h" #include "blob/digit.h" #include "blob/model.tflite.h" @@ -45,14 +52,20 @@ namespace { // The name of this function is important for Arduino compatibility. void setup() { +#if IS_USED(MODULE_TFLITE_MICRO) + tflite::InitializeTarget(); +#endif + // Set up logging. Google style is to avoid globals or statics because of // lifetime uncertainty, but since this has a trivial destructor it's okay. + // NOLINTNEXTLINE(runtime-global-variables) static tflite::MicroErrorReporter micro_error_reporter; error_reporter = µ_error_reporter; // Map the model into a usable data structure. This doesn't involve any // copying or parsing, it's a very lightweight operation. model = tflite::GetModel(model_tflite); + if (model->version() != TFLITE_SCHEMA_VERSION) { printf("Model provided is schema version %d not equal " "to supported version %d.", @@ -60,24 +73,17 @@ void setup() return; } - // Explicitly load required operators - static tflite::MicroMutableOpResolver micro_mutable_op_resolver; - micro_mutable_op_resolver.AddBuiltin( - tflite::BuiltinOperator_FULLY_CONNECTED, - tflite::ops::micro::Register_FULLY_CONNECTED(), 1, 4); - micro_mutable_op_resolver.AddBuiltin( - tflite::BuiltinOperator_SOFTMAX, - tflite::ops::micro::Register_SOFTMAX(), 1, 2); - micro_mutable_op_resolver.AddBuiltin( - tflite::BuiltinOperator_QUANTIZE, - tflite::ops::micro::Register_QUANTIZE()); - micro_mutable_op_resolver.AddBuiltin( - tflite::BuiltinOperator_DEQUANTIZE, - tflite::ops::micro::Register_DEQUANTIZE(), 1, 2); + // This pulls in all the operation implementations we need. + // NOLINTNEXTLINE(runtime-global-variables) +#if IS_USED(MODULE_TFLITE_MICRO) + static tflite::AllOpsResolver resolver; +#else + static tflite::ops::micro::AllOpsResolver resolver; +#endif // Build an interpreter to run the model with. static tflite::MicroInterpreter static_interpreter( - model, micro_mutable_op_resolver, tensor_arena, kTensorArenaSize, error_reporter); + model, resolver, tensor_arena, kTensorArenaSize, error_reporter); interpreter = &static_interpreter; // Allocate memory from the tensor_arena for the model's tensors. diff --git a/tests/pkg_tensorflow-lite/external_modules/mnist/mnist_mlp.py b/tests/pkg_tflite-micro/external_modules/mnist/mnist_mlp.py similarity index 100% rename from tests/pkg_tensorflow-lite/external_modules/mnist/mnist_mlp.py rename to tests/pkg_tflite-micro/external_modules/mnist/mnist_mlp.py diff --git a/tests/pkg_tensorflow-lite/external_modules/mnist/model.tflite b/tests/pkg_tflite-micro/external_modules/mnist/model.tflite similarity index 100% rename from tests/pkg_tensorflow-lite/external_modules/mnist/model.tflite rename to tests/pkg_tflite-micro/external_modules/mnist/model.tflite diff --git a/tests/pkg_tensorflow-lite/main.cpp b/tests/pkg_tflite-micro/main.cpp similarity index 100% rename from tests/pkg_tensorflow-lite/main.cpp rename to tests/pkg_tflite-micro/main.cpp diff --git a/tests/pkg_tensorflow-lite/tests/01-run.py b/tests/pkg_tflite-micro/tests/01-run.py similarity index 100% rename from tests/pkg_tensorflow-lite/tests/01-run.py rename to tests/pkg_tflite-micro/tests/01-run.py