-
Notifications
You must be signed in to change notification settings - Fork 2k
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/tensorflow-lite: add support to RIOT #12847
Conversation
8e9fa93
to
2c1fbcf
Compare
I pushed some code that adapts the magic_wand example but couldn't make it work yet: the interpreter remains stuck when calling it |
5efb072
to
e61834f
Compare
e61834f
to
56065f3
Compare
I found the problem: the stack size of the main thread was not large enough. Doubling it and the workflow now works. Unfortunately, I can't get a valid gesture detection. |
@aabadie could it be that the gesture model is (highly) dependent on the actual accelerometer type? |
And the new URL for the examples upstream are https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples |
It could be several things. In the examples, they are using different accelerometers (all ST though) and use the FIFO mode, which RIOT doesn't provide. Maybe the range of data is not the same. There was no model training example for the magic wand in the TensorFlow version used by this PR. It was added recently so it may help training a model that best fit the RIOT accelerometer data. |
I updated the package version and adapted to the new structure (was quite easy) but still no luck with the magic wand. Maybe it's time to train some model on the sensor data I'm using ? ;) |
I managed to get valid prediction with the magic wand model:
It's still very inaccurate and requires changes in the lsm6dsl driver. I think having the possibility to use the FIFO mode of the driver would also help. |
5854668
to
08d46d5
Compare
Finally, I replaced the magic_wand example with a new one based on the MNIST hand-written digit. The new example comes with Python scripts to train the model and to generate the input digit used by the application. This new example replicates the application of the utensor package. Regarding the magic wand, I'll provide it as a follow-up because it requires other changes in RIOT ST accelerrometer drivers (read data as float, require FIFO mode support). So no need to block this PR because of this. |
Note that the magic wand example is not about drawing a letter with the hand. It is about doing a gesture with an Harry Potter-like wand, and was inspired by J. Wang's example . Indeed FIFO support can be skipped: if one is really interested into this application (for next Halloween, etc.), one can train with a custom dataset, and using provided CNN/LTSM training ). |
b05df83
to
d2e5cc1
Compare
a01ff1c
to
925b570
Compare
Tensorflow released the 2.1 version this week. I'll check if this PR can be based on it, instead of using a random commit in master. |
So I gave a try to the 2.1 version and it seems to not contain the latest changes that are used in this PR. |
925b570
to
d0760a3
Compare
@fjmolinas, rebased now that #12846 is merged. Maybe I should squash since there was no review until now ? |
1eb9b23
to
785d6ca
Compare
I got a green light from @fjmolinas IRL, so squashed :) |
b4eec04
to
1b61e4f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some style comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested generating a new image (digit 1) and code correctly detected it, the test script doesn't work though since the digit detection is hardcoded:
main(): This is RIOT! (Version: 2020.01-devel-1738-g1b61e-pr-12847)
Digit prediction: 1
Timeout in expect script at "child.expect_exact("Digit prediction: 7")" (tests/pkg_tensorflow-lite/tests/01-run.py:8)
1b61e4f
to
d3999b2
Compare
@fjmolinas, I think I addressed all your comments. Let me know if it's ok for you now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aabadie one last comment please squash after amending.
b14016a
to
91f39c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK!
Contribution description
This PR adds support for TensorFlow Lite for microcontrollers to RIOT.
It based on 2 PRs
The integration into the build system can certainly be improved, so comments are welcome, of course.
The provided test application is just a plain copy (with .cc extensions changed into .cpp) of the hello-world sample, but there are more and it shouldn't be too difficult to adapt them.
cc'ing @adjih and @emmanuelsearch, who might be interested in testing this.
Testing procedure
Just build and run the test application:
It takes a bit of time to build but it's worth waiting :)
Issues/PRs references
Based on #12846 and
#12844