forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: add tensorflow magic wand sample
Adds Tensorflow Magic Wand sample to tree. Signed-off-by: Lauren Murphy <[email protected]>
- Loading branch information
1 parent
42e2a9e
commit 83a036d
Showing
24 changed files
with
2,920 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
cmake_minimum_required(VERSION 3.13.1) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(tensorflow_magic_wand) | ||
|
||
# Required for TensorFlow to compile properly | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics") | ||
|
||
target_sources(app PRIVATE | ||
src/main_functions.h | ||
src/constants.h | ||
src/magic_wand_model_data.h | ||
src/gesture_predictor.h | ||
src/output_handler.h | ||
src/assert.cc | ||
src/accelerometer_handler.cc | ||
src/accelerometer_handler.h | ||
src/main.cc | ||
src/main_functions.cc | ||
src/magic_wand_model_data.cc | ||
src/gesture_predictor.cc | ||
src/output_handler.cc | ||
boards/litex_vexriscv.overlay | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
.. _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 at least the below Kconfig options in | ||
your :file:`prj.conf` and set a flag in your :file:`CMakeLists.txt`. | ||
|
||
:file:`prj.conf`: | ||
|
||
.. code-block:: console | ||
CONFIG_CPLUSPLUS=y | ||
CONFIG_NEWLIB_LIBC=y | ||
CONFIG_TENSORFLOW_LITE_MICRO=y | ||
:file:`CMakeLists.txt`: | ||
|
||
.. code-block:: console | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-threadsafe-statics") | ||
Training | ||
******** | ||
Follow the instructions in the :file:`train/` directory to train your | ||
own model for use in the sample. |
17 changes: 17 additions & 0 deletions
17
samples/modules/tensorflow/magic_wand/boards/litex_vexriscv.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
CONFIG_ADXL345=y | ||
CONFIG_PWM=n | ||
CONFIG_PWM_LITEX=n |
38 changes: 38 additions & 0 deletions
38
samples/modules/tensorflow/magic_wand/boards/litex_vexriscv.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
==============================================================================*/ | ||
|
||
&i2c0 { | ||
label = "I2C0"; | ||
reg = <0xe0003000 0x4 0xe0003004 0x4>; | ||
|
||
adxl@1d { | ||
compatible = "adi,adxl345"; | ||
label = "accel-0"; | ||
reg = <0x1d>; | ||
}; | ||
|
||
}; | ||
|
||
&pwm0 { | ||
status = "disabled"; | ||
}; | ||
|
||
ð0 { | ||
status = "disabled"; | ||
}; | ||
|
||
&prbs0 { | ||
status = "disabled"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
CONFIG_CPLUSPLUS=y | ||
CONFIG_LIB_CPLUSPLUS=y | ||
CONFIG_NEWLIB_LIBC=y | ||
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y | ||
CONFIG_SENSOR=y | ||
CONFIG_NETWORKING=n | ||
CONFIG_MAIN_STACK_SIZE=4096 | ||
CONFIG_TENSORFLOW_LITE_MICRO=y |
128 changes: 128 additions & 0 deletions
128
samples/modules/tensorflow/magic_wand/renode/angle.data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
0 0 0 | ||
-766 132 709 | ||
-751 249 659 | ||
-714 314 630 | ||
-709 244 623 | ||
-707 230 659 | ||
-704 202 748 | ||
-714 219 728 | ||
-722 239 710 | ||
-744 116 612 | ||
-753 -49 570 | ||
-748 -279 527 | ||
-668 -664 592 | ||
-601 -635 609 | ||
-509 -559 606 | ||
-286 -162 536 | ||
-255 -144 495 | ||
-209 -85 495 | ||
6 416 698 | ||
-33 304 1117 | ||
-82 405 1480 | ||
-198 1008 1908 | ||
-229 990 1743 | ||
-234 934 1453 | ||
-126 838 896 | ||
-78 792 911 | ||
-27 741 918 | ||
114 734 960 | ||
135 613 959 | ||
152 426 1015 | ||
106 -116 1110 | ||
63 -314 1129 | ||
-12 -486 1179 | ||
-118 -656 1510 | ||
-116 -558 1553 | ||
-126 -361 1367 | ||
-222 -76 922 | ||
-210 -26 971 | ||
-194 50 1053 | ||
-178 72 1082 | ||
-169 100 1073 | ||
-162 133 1050 | ||
-156 226 976 | ||
-154 323 886 | ||
-130 240 1154 | ||
-116 124 916 | ||
-132 124 937 | ||
-153 115 981 | ||
-184 94 962 | ||
-177 85 1017 | ||
-173 92 1027 | ||
-168 158 1110 | ||
-181 101 1030 | ||
-180 139 1054 | ||
-152 10 1044 | ||
-169 74 1007 |
Oops, something went wrong.