Has anyone used TensorFlow Lite Micro with STM32 project recently?
Has anyone used TensorFlow Lite Micro with STM32 project recently? I am trying to do it on my own but I don't even know what to build and include in my project.There is no good documentation or tutorials for it.
22 Replies
You are in luck, we have an engineering session going on with this plus you have @undefined.elf and @wafa_ath who should be very proficient at this.
Nice, I'll look forward to it then. I'm doing Harvard TinyML course on edX. It's good but they're providing libraries to do everything in their arduino kit. I already have an STM32 board with me so I want to do it myself
Hi @araki , can you tell more about the project you are doing
I had the same goal man
Hi @wafa_ath I have a trained tflite model for keyword spotting. I want to run the inference on my STM32F407 board using tflite micro. I am just learning embedded programming so I am a bit stuck on how to even go about doing this. Most tutorials are outdated. And it is now using bazel build system, am I supposed to build it as a library and link it during my stm project compilation?
Ah, can you inlcude the lib and build it with your source? What tutorial are you using
So you already trained your model ?
yep, I have a model. I just want to know how to invoke it from an STM32 project. I'm using STM32CUBE IDE
I'm trying to follow one from digikey but it is outdated. It was written before tflite-micro repository got separated and the buidsystem seems to be changed too
have you looked at this guide https://ai.google.dev/edge/litert/microcontrollers/get_started
Google AI for Developers
Get started with microcontrollers | Google AI Edge | Google AI ...
Also @araki check this https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/docs/new_platform_support.md
GitHub
tflite-micro/tensorflow/lite/micro/docs/new_platform_support.md at ...
Infrastructure to enable deployment of ML models to low-power resource-constrained embedded targets (including microcontrollers and digital signal processors). - tensorflow/tflite-micro
https://ai.google.dev/edge/litert/microcontrollers/get_started#1_include_the_library_headers
I was about to follow this as well. This gives information about running it but only if you follow it's own generated structure. I'll look into it more. Thanks for the links
Google AI for Developers
Get started with microcontrollers | Google AI Edge | Google AI ...
this should work as well.
So fter converting your model to tflite Micro, you also need to convert it to C array. you need to download the TensorFlow Lite Micro source code and integrate it into your STM32 project. see the tutorial @ZacckOsiemo sends that should work
yep, I seem to understand it but I just don't know how to include the source for those header files.
https://ai.google.dev/edge/litert/microcontrollers/library#generate_projects_for_other_platforms
I think this should work but the problem is, there is no "generate_projects" rule in the Makefile
Google AI for Developers
Understand the C++ library | Google AI Edge | Google AI for Dev...
Yeah, just grab the tflite-micro source files (like the ones in micro/, schema/, and flatbuffers/include/) and drop them into your STM32 project. Make sure the include paths are set up right, and you’re good to go. Don’t worry about the generate_projects it's not needed for STM32.
Ok, I think I got tflite micro integrated into my project. Now I have to actually write error free code. I can't get the resolver working but that's for tomorrow. I'm all out of brain juice for today 😅
I'm new to this so I really appreciate your time and help. Thanks a lot @wafa_ath @ZacckOsiemo
very welcome , anytime
can we see your code please?
Late reply, but I got it working using the generated file structed by the following command. It also gives example c file so I'm simply following that code.
I still have to copy paste additional folders (following the compile errors). But now I'm getting errors from the TFLite library code itself.
@undefined.elf is working on this now, perhaps have a call with him.
I almost succeeded just one more step left
I hope after that we can chill
which C++ standard are you using?