TensorFlow Magic Wand sample¶
Overview¶
This sample application shows how to use TensorFlow Lite Micro to run a 20 kilobyte neural network model that recognizes gestures from an accelerometer.
Note
This README and sample have been modified from the TensorFlow Magic Wand sample for Zephyr and the Antmicro tutorial on Renode emulation for TensorFlow.
Building and Running¶
The application can be built for the LiteX VexRiscv for emulation in Renode as follows:
west build -b litex_vexriscv samples/tensorflow/magic_wand
Once the application is built, download and install Renode 1.12 or higher as a package following the instructions in the Renode GitHub README and start the emulator:
renode -e "set zephyr_elf @./build/zephyr/zephyr.elf; s @./renode/litex-vexriscv-tflite.resc"
Sample Output¶
The Renode-emulated LiteX/VexRiscv board is fed data that the application recognizes as a series of alternating ring and slope gestures.
Got accelerometer, label: accel-0
RING:
*
* *
* *
* *
* *
* *
*
SLOPE:
*
*
*
*
*
*
*
* * * * * * * *
RING:
*
* *
* *
* *
* *
* *
*
SLOPE:
*
*
*
*
*
*
*
* * * * * * * *
Modifying Sample for Your Own Project¶
It is recommended that you copy and modify one of the two TensorFlow
samples when creating your own TensorFlow project. To build with
TensorFlow, you must enable at least the below Kconfig options in
your prj.conf
and set a flag in your CMakeLists.txt
.
prj.conf
:
CONFIG_CPLUSPLUS=y
CONFIG_NEWLIB_LIBC=y
CONFIG_TENSORFLOW_LITE_MICRO=y
CMakeLists.txt
:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics")
Training¶
Follow the instructions in the train/
directory to train your
own model for use in the sample.