zephyr/samples/modules/tflite-micro/magic_wand
Benjamin Cabé b4b623c26c doc: use proper pygment for .conf code-blocks
config file snippets should use "cfg" pygment to get proper highlighting
This commit updates all occurences where "kconfig" or other languages
were used.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2024-06-20 14:07:32 -04:00
..
boards samples: modules: tflite-micro: magic_wand: add missing CONFIG_I2C=y 2022-08-05 12:55:51 +02:00
renode docs, samples: tflite-micro: change tensorflow to tensorflow lite micro 2021-08-24 07:26:08 -04:00
src samples: modules: tflite-micro: remove incorrect check 2024-01-18 12:09:53 +00:00
train treewide: Disable automatic argparse argument shortening 2023-01-26 20:12:36 +09:00
CMakeLists.txt cmake: remove stray overlay file from target sources 2024-04-05 21:54:12 -05:00
prj.conf samples: Switch from NEWLIB_LIBC to REQUIRES_FULL_LIBC 2023-10-25 08:32:06 +02:00
README.rst doc: use proper pygment for .conf code-blocks 2024-06-20 14:07:32 -04:00
sample.yaml tests: cleanup metadata and filtering 2023-06-13 09:38:27 -04:00

.. _tensorflow_magic_wand:

TensorFlow Lite Micro 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`_.

.. _the TensorFlow Magic Wand sample for Zephyr:
    https://github.com/tensorflow/tflite-micro-arduino-examples/tree/main/examples/magic_wand

.. _the Antmicro tutorial on Renode emulation for TensorFlow:
    https://github.com/antmicro/litex-vexriscv-tensorflow-lite-demo

Building and Running
********************

Add the tflite-micro module to your West manifest and pull it:

.. code-block:: console

    west config manifest.project-filter -- +tflite-micro
    west update

The application can be built for the :ref:`litex-vexriscv` for
emulation in Renode as follows:

.. zephyr-app-commands::
   :zephyr-app: samples/modules/tflite-micro/magic_wand
   :host-os: unix
   :board: litex_vexriscv
   :goals: build
   :compact:

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:

.. code-block:: console

    renode -e "set zephyr_elf @./build/zephyr/zephyr.elf; s @./samples/modules/tflite-micro/magic_wand/renode/litex-vexriscv-tflite.resc"

.. _download and install Renode 1.12 or higher as a package:
    https://github.com/renode/renode/releases/

.. _Renode GitHub README:
    https://github.com/renode/renode/blob/master/README.rst

Sample Output
=============

The Renode-emulated LiteX/VexRiscv board is fed data that the
application recognizes as a series of alternating ring and slope
gestures.

.. code-block:: console

    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 the below Kconfig options in your :file:`prj.conf`:

.. code-block:: cfg

    CONFIG_CPP=y
    CONFIG_REQUIRES_FULL_LIBC=y
    CONFIG_TENSORFLOW_LITE_MICRO=y

Training
********
Follow the instructions in the :file:`train/` directory to train your
own model for use in the sample.