zephyr/samples/modules/tensorflow/magic_wand
Lauren Murphy f77d5c5c53 samples: tensorflow: change from file list to glob in cmakelists.txt
Changes CMakeLists.txt in TensorFlow samples from explicit file
list to a GLOB capturing src/* to make TensorFlow samples consistent
with other samples in tree.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2021-05-20 20:59:45 -04:00
..
boards
renode
src
train
CMakeLists.txt samples: tensorflow: change from file list to glob in cmakelists.txt 2021-05-20 20:59:45 -04:00
prj.conf
README.rst samples: tensorflow: fix documentation 2021-05-20 20:59:45 -04:00
sample.yaml

.. _tensorflow_magic_wand:

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`_.

.. _the TensorFlow Magic Wand sample for Zephyr:
    https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples/magic_wand

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

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

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

.. zephyr-app-commands::
   :zephyr-app: samples/tensorflow/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 @./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`.

:file:`prj.conf`:

.. code-block:: console

    CONFIG_CPLUSPLUS=y
    CONFIG_NEWLIB_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.