Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/tflite-micro: add support and deprecate tensorflow-lite #17908

Merged
merged 7 commits into from Apr 8, 2022

Conversation

aabadie
Copy link
Contributor

@aabadie aabadie commented Apr 8, 2022

Contribution description

This PR introduces the tflite-micro framework as a package to replace the actual tensorflow-lite package.
The main advantage of tflite-micro is that it's a subset of tensorflow, that only targets microcontrollers. tflite-micro is automatically synchronized with the upstream tensorflow lite repo.
As a result, it takes less time to fetch with git and also less space on disk.

The actual tensorflow-lite package is updated to 2.2.2 and deprecated by this PR but the test application, renamed tests/pkg_tflite-micro and slightly adapted, is still compatible with it (that's also why 2.2.2 is required).

To add support for tflite-micro, several things were needed:

  • add the ruy matrix multiplication library as a package
  • bump flatbuffer package to v2.0.0

Even if not strictly required, gemmlowp version was also updated.

Testing procedure

The tflite-micro port was tested on native, cortexm4 (nucleo-l4) and esp32. It doesn't work on riscv even if it builds fine.

native
$ BUILD_IN_DOCKER=1 make -C tests/pkg_tflite-micro flash test --no-print-directory 
Launching build container using image "riot/riotbuild:latest".
docker run --rm --tty --user $(id -u) -v '/usr/share/zoneinfo/Europe/Paris:/etc/localtime:ro' -v '/work/riot/RIOT:/data/riotbuild/riotbase:delegated' -v '/home/aabadie/.cargo/registry:/data/riotbuild/.cargo/registry:delegated' -v '/home/aabadie/.cargo/git:/data/riotbuild/.cargo/git:delegated' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'RIOTPROJECT=/data/riotbuild/riotbase' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles'       -e 'DISABLE_MODULE=cortexm_fpu' -e 'DEFAULT_MODULE=test_utils_interactive_sync test_utils_print_stack_usage' -e 'FEATURES_REQUIRED=' -e 'FEATURES_BLACKLIST=' -e 'FEATURES_OPTIONAL=' -e 'USEMODULE=mnist' -e 'USEPKG=tflite-micro' -e 'KCONFIG_ADD_CONFIG='  -w '/data/riotbuild/riotbase/tests/pkg_tflite-micro/' 'riot/riotbuild:latest' make  'EXTERNAL_MODULE_DIRS=/data/riotbuild/riotbase/tests/pkg_tflite-micro/external_modules'   
Building application "tests_pkg_tflite-micro" for "native" with MCU "native".

"make" -C /data/riotbuild/riotbase/pkg/flatbuffers/ 
"make" -C /data/riotbuild/riotbase/pkg/gemmlowp/ 
"make" -C /data/riotbuild/riotbase/pkg/ruy/ 
"make" -C /data/riotbuild/riotbase/pkg/tflite-micro/ 
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/c -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-c.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/core/api -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-core-api.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/kernels -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-kernels.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/kernels/internal -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-kernels-internal.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/kernels/internal/reference -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-kernels-internal-reference.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/micro -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-micro.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/micro/kernels -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-micro-kernels.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/micro/memory_planner -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-micro-memory-planner.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/schema -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-schema.mk
"make" -C /data/riotbuild/riotbase/boards/common/init
"make" -C /data/riotbuild/riotbase/boards/native
"make" -C /data/riotbuild/riotbase/boards/native/drivers
"make" -C /data/riotbuild/riotbase/core
"make" -C /data/riotbuild/riotbase/core/lib
"make" -C /data/riotbuild/riotbase/cpu/native
"make" -C /data/riotbuild/riotbase/cpu/native/periph
"make" -C /data/riotbuild/riotbase/cpu/native/stdio_native
"make" -C /data/riotbuild/riotbase/drivers
"make" -C /data/riotbuild/riotbase/drivers/periph_common
"make" -C /data/riotbuild/riotbase/sys
"make" -C /data/riotbuild/riotbase/sys/auto_init
"make" -C /data/riotbuild/riotbase/sys/cpp11-compat
"make" -C /data/riotbuild/riotbase/sys/cpp_new_delete
"make" -C /data/riotbuild/riotbase/sys/div
"make" -C /data/riotbuild/riotbase/sys/frac
"make" -C /data/riotbuild/riotbase/sys/test_utils/interactive_sync
"make" -C /data/riotbuild/riotbase/sys/test_utils/print_stack_usage
"make" -C /data/riotbuild/riotbase/sys/timex
"make" -C /data/riotbuild/riotbase/sys/ztimer
"make" -C /data/riotbuild/riotbase/sys/ztimer64
"make" -C /data/riotbuild/riotbase/tests/pkg_tflite-micro/external_modules/mnist
   text	   data	    bss	    dec	    hex	filename
 531766	  91441	  59428	 682635	  a6a8b	/data/riotbuild/riotbase/tests/pkg_tflite-micro/bin/native/tests_pkg_tflite-micro.elf
r
/work/riot/RIOT/tests/pkg_tflite-micro/bin/native/tests_pkg_tflite-micro.elf /dev/ttyACM0 
RIOT native interrupts/signals initialized.
RIOT native board initialized.
RIOT native hardware initialization complete.

Help: Press s to start test, r to print it is ready
READY
s
START
main(): This is RIOT! (Version: 2022.04-devel-1111-ge56b5-pr/pkg/tflite-micro)
Digit prediction: 7


nucleo-l476rg
$ BUILD_IN_DOCKER=1 make BOARD=nucleo-l476rg -C tests/pkg_tflite-micro flash test --no-print-directory 
Launching build container using image "riot/riotbuild:latest".
docker run --rm --tty --user $(id -u) -v '/usr/share/zoneinfo/Europe/Paris:/etc/localtime:ro' -v '/work/riot/RIOT:/data/riotbuild/riotbase:delegated' -v '/home/aabadie/.cargo/registry:/data/riotbuild/.cargo/registry:delegated' -v '/home/aabadie/.cargo/git:/data/riotbuild/.cargo/git:delegated' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'RIOTPROJECT=/data/riotbuild/riotbase' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles'      -e 'BOARD=nucleo-l476rg' -e 'DISABLE_MODULE=cortexm_fpu' -e 'DEFAULT_MODULE=test_utils_interactive_sync test_utils_print_stack_usage' -e 'FEATURES_REQUIRED=' -e 'FEATURES_BLACKLIST=' -e 'FEATURES_OPTIONAL=' -e 'USEMODULE=mnist' -e 'USEPKG=tflite-micro' -e 'KCONFIG_ADD_CONFIG='  -w '/data/riotbuild/riotbase/tests/pkg_tflite-micro/' 'riot/riotbuild:latest' make 'BOARD=nucleo-l476rg' 'EXTERNAL_MODULE_DIRS=/data/riotbuild/riotbase/tests/pkg_tflite-micro/external_modules'   
Building application "tests_pkg_tflite-micro" for "nucleo-l476rg" with MCU "stm32".

"make" -C /data/riotbuild/riotbase/pkg/flatbuffers/ 
"make" -C /data/riotbuild/riotbase/pkg/gemmlowp/ 
"make" -C /data/riotbuild/riotbase/pkg/ruy/ 
"make" -C /data/riotbuild/riotbase/pkg/tflite-micro/ 
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/c -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-c.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/core/api -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-core-api.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/kernels -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-kernels.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/kernels/internal -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-kernels-internal.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/kernels/internal/reference -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-kernels-internal-reference.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/micro -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-micro.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/micro/kernels -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-micro-kernels.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/micro/memory_planner -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-micro-memory-planner.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/schema -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-schema.mk
"make" -C /data/riotbuild/riotbase/boards/common/init
"make" -C /data/riotbuild/riotbase/boards/nucleo-l476rg
"make" -C /data/riotbuild/riotbase/boards/common/nucleo
"make" -C /data/riotbuild/riotbase/core
"make" -C /data/riotbuild/riotbase/core/lib
"make" -C /data/riotbuild/riotbase/cpu/stm32
"make" -C /data/riotbuild/riotbase/cpu/cortexm_common
"make" -C /data/riotbuild/riotbase/cpu/cortexm_common/periph
"make" -C /data/riotbuild/riotbase/cpu/stm32/periph
"make" -C /data/riotbuild/riotbase/cpu/stm32/stmclk
"make" -C /data/riotbuild/riotbase/cpu/stm32/vectors
"make" -C /data/riotbuild/riotbase/drivers
"make" -C /data/riotbuild/riotbase/drivers/periph_common
"make" -C /data/riotbuild/riotbase/sys
"make" -C /data/riotbuild/riotbase/sys/auto_init
"make" -C /data/riotbuild/riotbase/sys/cpp11-compat
"make" -C /data/riotbuild/riotbase/sys/cpp_new_delete
"make" -C /data/riotbuild/riotbase/sys/div
"make" -C /data/riotbuild/riotbase/sys/frac
"make" -C /data/riotbuild/riotbase/sys/isrpipe
"make" -C /data/riotbuild/riotbase/sys/malloc_thread_safe
"make" -C /data/riotbuild/riotbase/sys/newlib_syscalls_default
"make" -C /data/riotbuild/riotbase/sys/pm_layered
"make" -C /data/riotbuild/riotbase/sys/stdio_uart
"make" -C /data/riotbuild/riotbase/sys/test_utils/interactive_sync
"make" -C /data/riotbuild/riotbase/sys/test_utils/print_stack_usage
"make" -C /data/riotbuild/riotbase/sys/timex
"make" -C /data/riotbuild/riotbase/sys/tsrb
"make" -C /data/riotbuild/riotbase/sys/ztimer
"make" -C /data/riotbuild/riotbase/sys/ztimer64
"make" -C /data/riotbuild/riotbase/tests/pkg_tflite-micro/external_modules/mnist
   text	   data	    bss	    dec	    hex	filename
 267832	    632	  13600	 282064	  44dd0	/data/riotbuild/riotbase/tests/pkg_tflite-micro/bin/nucleo-l476rg/tests_pkg_tflite-micro.elf
/work/riot/RIOT/dist/tools/openocd/openocd.sh flash /work/riot/RIOT/tests/pkg_tflite-micro/bin/nucleo-l476rg/tests_pkg_tflite-micro.elf
### Flashing Target ###
Open On-Chip Debugger 0.11.0+dev-00551-gaad871805 (2022-01-06-14:44)
Licensed under GNU GPL v2
For bug reports, read
	http://openocd.org/doc/doxygen/bugs.html
hla_swd
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : DEPRECATED target event trace-config; use TPIU events {pre,post}-{enable,disable}
srst_only separate srst_nogate srst_open_drain connect_assert_srst

Info : clock speed 500 kHz
Info : STLINK V2J28M18 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.244737
Info : stm32l4x.cpu: Cortex-M4 r0p1 processor detected
Info : stm32l4x.cpu: target has 6 breakpoints, 4 watchpoints
Info : starting gdb server for stm32l4x.cpu on 0
Info : Listening on port 36173 for gdb connections
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* stm32l4x.cpu       hla_target little stm32l4x.cpu       reset

Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x080006f4 msp: 0x20000200
Info : device idcode = 0x10076415 (STM32L47/L48xx - Rev 4 : 0x1007)
Info : RDP level 0 (0xAA)
Info : flash size = 1024kbytes
Info : flash mode : dual-bank
Warn : Adding extra erase range, 0x080418b0 .. 0x08041fff
auto erase enabled
wrote 268464 bytes from file /work/riot/RIOT/tests/pkg_tflite-micro/bin/nucleo-l476rg/tests_pkg_tflite-micro.elf in 11.516569s (22.765 KiB/s)

verified 268464 bytes in 7.812533s (33.558 KiB/s)

Info : Unable to match requested speed 500 kHz, using 480 kHz
Info : Unable to match requested speed 500 kHz, using 480 kHz
shutdown command invoked
Done flashing
r
/work/riot/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyACM0" -b "115200" --no-reconnect --noprefix --no-repeat-command-on-empty-line 
Twisted not available, please install it if you want to use pyterm's JSON capabilities
Connect to serial port /dev/ttyACM0
Welcome to pyterm!
Type '/exit' to exit.
READY
s
START
main(): This is RIOT! (Version: 2022.04-devel-1111-ge56b5-pr/pkg/tflite-micro)
Digit prediction: 7


esp32-wroom-32
$ BUILD_IN_DOCKER=1 make BOARD=esp32-wroom-32 -C tests/pkg_tflite-micro flash test --no-print-directory 
Launching build container using image "riot/riotbuild:latest".
docker run --rm --tty --user $(id -u) -v '/usr/share/zoneinfo/Europe/Paris:/etc/localtime:ro' -v '/work/riot/RIOT:/data/riotbuild/riotbase:delegated' -v '/home/aabadie/.cargo/registry:/data/riotbuild/.cargo/registry:delegated' -v '/home/aabadie/.cargo/git:/data/riotbuild/.cargo/git:delegated' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'RIOTPROJECT=/data/riotbuild/riotbase' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles'      -e 'BOARD=esp32-wroom-32' -e 'DISABLE_MODULE=cortexm_fpu' -e 'DEFAULT_MODULE=test_utils_interactive_sync test_utils_print_stack_usage' -e 'FEATURES_REQUIRED=' -e 'FEATURES_BLACKLIST=' -e 'FEATURES_OPTIONAL=' -e 'USEMODULE=mnist' -e 'USEPKG=tflite-micro' -e 'KCONFIG_ADD_CONFIG='  -w '/data/riotbuild/riotbase/tests/pkg_tflite-micro/' 'riot/riotbuild:latest' make 'BOARD=esp32-wroom-32' 'EXTERNAL_MODULE_DIRS=/data/riotbuild/riotbase/tests/pkg_tflite-micro/external_modules'   
Building application "tests_pkg_tflite-micro" for "esp32-wroom-32" with MCU "esp32".

"make" -C /data/riotbuild/riotbase/pkg/esp32_sdk/ 
"make" -C /data/riotbuild/riotbase/pkg/esp32_sdk_libs/ 
"make" -C /data/riotbuild/riotbase/pkg/flatbuffers/ 
"make" -C /data/riotbuild/riotbase/pkg/gemmlowp/ 
"make" -C /data/riotbuild/riotbase/pkg/ruy/ 
"make" -C /data/riotbuild/riotbase/pkg/tflite-micro/ 
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/c -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-c.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/core/api -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-core-api.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/kernels -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-kernels.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/kernels/internal -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-kernels-internal.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/kernels/internal/reference -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-kernels-internal-reference.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/micro -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-micro.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/micro/kernels -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-micro-kernels.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/micro/memory_planner -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-micro-memory-planner.mk
"make" -C /data/riotbuild/riotbase/build/pkg/tflite-micro/tensorflow/lite/schema -f /data/riotbuild/riotbase/pkg/tflite-micro/tflite-schema.mk
"make" -C /data/riotbuild/riotbase/boards/common/init
"make" -C /data/riotbuild/riotbase/boards/esp32-wroom-32
"make" -C /data/riotbuild/riotbase/boards/common/esp32
"make" -C /data/riotbuild/riotbase/core
"make" -C /data/riotbuild/riotbase/core/lib
"make" -C /data/riotbuild/riotbase/cpu/esp32
"make" -C /data/riotbuild/riotbase/cpu/esp32/freertos
"make" -C /data/riotbuild/riotbase/cpu/esp32/periph
"make" -C /data/riotbuild/riotbase/cpu/esp32/vendor
"make" -C /data/riotbuild/riotbase/cpu/esp32/vendor/esp-idf
"make" -C /data/riotbuild/riotbase/cpu/esp32/vendor/esp-idf/driver
"make" -C /data/riotbuild/riotbase/cpu/esp32/vendor/esp-idf/esp32
"make" -C /data/riotbuild/riotbase/cpu/esp32/vendor/esp-idf/soc
"make" -C /data/riotbuild/riotbase/cpu/esp32/vendor/esp-idf/spi_flash
"make" -C /data/riotbuild/riotbase/cpu/esp_common
"make" -C /data/riotbuild/riotbase/cpu/esp_common/freertos
"make" -C /data/riotbuild/riotbase/cpu/esp_common/periph
"make" -C /data/riotbuild/riotbase/cpu/esp_common/vendor
"make" -C /data/riotbuild/riotbase/cpu/esp_common/vendor/xtensa
"make" -C /data/riotbuild/riotbase/drivers
"make" -C /data/riotbuild/riotbase/drivers/periph_common
"make" -C /data/riotbuild/riotbase/sys
"make" -C /data/riotbuild/riotbase/sys/auto_init
"make" -C /data/riotbuild/riotbase/sys/cpp11-compat
"make" -C /data/riotbuild/riotbase/sys/cpp_new_delete
"make" -C /data/riotbuild/riotbase/sys/div
"make" -C /data/riotbuild/riotbase/sys/frac
"make" -C /data/riotbuild/riotbase/sys/isrpipe
"make" -C /data/riotbuild/riotbase/sys/log
"make" -C /data/riotbuild/riotbase/sys/luid
"make" -C /data/riotbuild/riotbase/sys/newlib_syscalls_default
"make" -C /data/riotbuild/riotbase/sys/pm_layered
"make" -C /data/riotbuild/riotbase/sys/posix/pthread
"make" -C /data/riotbuild/riotbase/sys/random
"make" -C /data/riotbuild/riotbase/sys/stdio_uart
"make" -C /data/riotbuild/riotbase/sys/test_utils/interactive_sync
"make" -C /data/riotbuild/riotbase/sys/test_utils/print_stack_usage
"make" -C /data/riotbuild/riotbase/sys/timex
"make" -C /data/riotbuild/riotbase/sys/tsrb
"make" -C /data/riotbuild/riotbase/sys/ztimer
"make" -C /data/riotbuild/riotbase/sys/ztimer64
"make" -C /data/riotbuild/riotbase/tests/pkg_tflite-micro/external_modules/mnist
esptool.py v3.2-dev
Merged 1 ELF section
Parsing CSV input...
   text	   data	    bss	    dec	    hex	filename
 213997	 170556	  18320	 402873	  625b9	/data/riotbuild/riotbase/tests/pkg_tflite-micro/bin/esp32-wroom-32/tests_pkg_tflite-micro.elf
/work/riot/RIOT/dist/tools/esptools/esptool_v3.2.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 --before default_reset write_flash -z --flash_mode dout --flash_freq 40m    0x1000 /work/riot/RIOT/cpu/esp32/bin/bootloader.bin 0x8000 /work/riot/RIOT/tests/pkg_tflite-micro/bin/esp32-wroom-32/partitions.bin 0x10000 /work/riot/RIOT/tests/pkg_tflite-micro/bin/esp32-wroom-32/tests_pkg_tflite-micro.elf.bin
esptool.py v3.2-dev
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 80:7d:3a:fd:d9:90
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00001000 to 0x00005fff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x00010000 to 0x0006dfff...
Flash params set to 0x0310
Compressed 18640 bytes to 11444...
Wrote 18640 bytes (11444 compressed) at 0x00001000 in 0.6 seconds (effective 257.5 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 85...
Wrote 3072 bytes (85 compressed) at 0x00008000 in 0.1 seconds (effective 384.4 kbit/s)...
Hash of data verified.
Compressed 384672 bytes to 212285...
Wrote 384672 bytes (212285 compressed) at 0x00010000 in 5.0 seconds (effective 615.5 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
r
/work/riot/RIOT/dist/tools/pyterm/pyterm -p "/dev/ttyUSB0" -b "115200" --no-reconnect --noprefix --no-repeat-command-on-empty-line 
Twisted not available, please install it if you want to use pyterm's JSON capabilities
Connect to serial port /dev/ttyUSB0
Welcome to pyterm!
Type '/exit' to exit.
READY
s
START
main(): This is RIOT! (Version: 2022.04-devel-1111-ge56b5-pr/pkg/tflite-micro)
Digit prediction: 7

Murdock should catch other issues.

Issues/PRs references

closes #16416

@github-actions github-actions bot added Area: build system Area: Build system Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports Area: tests Area: tests and testing framework labels Apr 8, 2022
@aabadie aabadie added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 8, 2022
Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good and tests output has been provided.
Thank you for packaging all of this!

USEPKG += tflite-micro

# TensorFlow-Lite crashes on M4/M7 CPUs when FPU is enabled, so disable it by
# default for now
Copy link
Contributor

@benpicco benpicco Apr 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you open an issue for that?
Smells fishy.

Does this package make use of the DSP instructions found in those cores? Might be that we are not handling those registers properly yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you open an issue for that?

Sure. I tested without just to be sure and on cortexm it ends up with a hardfault. Maybe that's the same issue on riscv ?

Does this package make use of the DSP instructions found in those cores? Might be that we are not handling those registers properly yet.

There's room for improvements. On cortex m4/7, we could enable CMSIS-NN primitives to speed up the inference (40% gain).
More generally, we could package kissfft and see how to support more complex scenario for keyword spotting. I was not able to make the whole stuff to work when I ported tensorflow-lite (back in 2019/2020) but maybe things have evolved positively since then.
I'm also looking into the edge-impulse SDK (I have a branch) which also relies on tensorflow and is easier to package, all third-party libraries are present in the repo, so can adapted with only one package.

@kfessel
Copy link
Contributor

kfessel commented Apr 8, 2022

Since this has a component of git clone-bytes and size of clones i would like to promote #16316

@benpicco
Copy link
Contributor

benpicco commented Apr 8, 2022

Looks like Makefile.ci needs an update

@aabadie
Copy link
Contributor Author

aabadie commented Apr 8, 2022

Looks like Makefile.ci needs an update

I'm running locally the create-Makefile.ci target but it will take some time (each build is time consuming...)

@aabadie aabadie enabled auto-merge April 8, 2022 12:44
@aabadie aabadie requested a review from kaspar030 as a code owner April 8, 2022 13:42
@github-actions github-actions bot added the Area: CI Area: Continuous Integration of RIOT components label Apr 8, 2022
@aabadie aabadie disabled auto-merge April 8, 2022 13:42
@aabadie aabadie enabled auto-merge April 8, 2022 15:19
@github-actions github-actions bot removed the Area: CI Area: Continuous Integration of RIOT components label Apr 8, 2022
@aabadie aabadie merged commit 4c125db into RIOT-OS:master Apr 8, 2022
@aabadie aabadie deleted the pr/pkg/tflite-micro branch April 8, 2022 16:37
@OlegHahm OlegHahm added this to the Release 2022.04 milestone Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system Area: doc Area: Documentation Area: Kconfig Area: Kconfig integration Area: pkg Area: External package ports Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants