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
ZacckOsiemo
ZacckOsiemo5w ago
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.
araki
araki5w ago
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
wafa_ath
wafa_ath5w ago
Hi @araki , can you tell more about the project you are doing
undefined.elf
undefined.elf5w ago
I had the same goal man
araki
araki5w ago
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?
ZacckOsiemo
ZacckOsiemo5w ago
Ah, can you inlcude the lib and build it with your source? What tutorial are you using
wafa_ath
wafa_ath5w ago
So you already trained your model ?
araki
araki5w ago
yep, I have a model. I just want to know how to invoke it from an STM32 project. I'm using STM32CUBE IDE
araki
araki5w ago
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
ZacckOsiemo
ZacckOsiemo5w ago
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
araki
araki5w ago
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
ZacckOsiemo
ZacckOsiemo5w ago
this should work as well.
wafa_ath
wafa_ath5w ago
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
araki
araki5w ago
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
wafa_ath
wafa_ath5w ago
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.
araki
araki5w ago
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
wafa_ath
wafa_ath5w ago
very welcome , anytime
ZacckOsiemo
ZacckOsiemo5w ago
can we see your code please?
araki
araki5w ago
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.
python3 tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py \
-e hello_world \
-e micro_speech \
-e person_detection \
/tmp/tflm-tree
python3 tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py \
-e hello_world \
-e micro_speech \
-e person_detection \
/tmp/tflm-tree
I still have to copy paste additional folders (following the compile errors). But now I'm getting errors from the TFLite library code itself.
attachment 0
ZacckOsiemo
ZacckOsiemo5w ago
@undefined.elf is working on this now, perhaps have a call with him.
undefined.elf
undefined.elf5w ago
I almost succeeded just one more step left I hope after that we can chill which C++ standard are you using?

Did you find this page helpful?