How to include TensorFlow Lite Library into my Project

Greetings!
I am quite confused on how to use TensorFlow Lite for my Project. I use a STM32L476-Board and it is running on Mbed. I created the TensorFlow and some third party folders using this guide: tflite-micro/new_platform_support.md at main · tensorflow/tflite-micro · GitHub.

Afterwards I included both folders in the lib-folder inside my project. The structure looks like this:

|--lib
|  |
|  |--tensorflow
|  |  |--lite
|  |  |  |--c
|  |  |  |  |--some files
|  |  |  |--core
|  |  |  |  |--some files
|  |  |  |--kernels
|  |  |  |  |--some files
|  |  |  |--micro
|  |  |  |  |--some files
|  |
|  |--third_party
|  |  |--flatbuffer
|  |  |--gemmlowp
|  |  |--kissfft
|  |  |--ruy

Without any changes it won’t compile. So I tried a lot of things inside the platform.ini-file like:

  • adding the folders to lib_deps …
lib_deps =
     third_party
     tensorflow

… changing the Library Dependency Finder-mode (currently deep+) and using some buildflags

build_flags =
     -I $PROJECT_DIR/lib/third_party/
     -I $PROJECT_DIR/lib/third_party/flatbuffers/include
     -I $PROJECT_DIR/lib/third_party/gemmlowp/fixedpoint
     -I $PROJECT_DIR/lib/third_party/gemmlowp/internal
     -I $PROJECT_DIR/lib/third_party/kissfft/
     -I $PROJECT_DIR/lib/third_party/kissfft/tools
     -I $PROJECT_DIR/lib/third_party/ruy

It still fails and shows errors like:

Compiling .pio\build\nucleo_l476rg\src\main.o
Generating LD script .pio\build\nucleo_l476rg\stm32l476xg.ld.link_script.ld
Compiling .pio\build\nucleo_l476rg\libcfa\third_party\kissfft\kiss_fft.o
Compiling .pio\build\nucleo_l476rg\libcfa\third_party\kissfft\tools\kiss_fftr.o
Compiling .pio\build\nucleo_l476rg\libc05\tensorflow\lite\c\common.o
Compiling .pio\build\nucleo_l476rg\libc05\tensorflow\lite\core\api\error_reporter.o
lib\tensorflow\lite\c\common.cc:16:10: fatal error: tensorflow/lite/c/common.h: No such file or directory
   16 | #include "tensorflow/lite/c/common.h"

I maybe could fix this particular problem by adding a build_flag for the tensorflow-folders aswell, but then it breaks something when compiling Mbed-libraries:

Compiling .pio\build\nucleo_l476rg\FrameworkMbedconnectivity\mbedtls\source\aesni.o
In file included from C:\Users\andre\.platformio\packages\framework-mbed\connectivity\mbedtls\source\aes.c:26:
lib\tensorflow\lite\c/common.h:43:10: fatal error: tensorflow/lite/c/c_api_types.h: No such file or directory
   43 | #include "tensorflow/lite/c/c_api_types.h"  // IWYU pragma: export

I think there is an easier way to include the libraries, but I am honestly not sure how after the attempts I already did. I would really appreciate some help. Thank you!

1 Like

Try addign another -I $PROJECT_DIR/lib so that tensorflow/lite/c/c_api_types type paths can be resolved.

2 Likes

Thanks a lot, it works now after some small fixes in the includes!
The funny thing is, that I already had -I $PROJECT_DIR/lib inside my platform.ini a few hours ago, but it didn’t work back then. Some changes made it work now, yay!

Would you mind posting your full platformio.ini? I have the same problem. I have downloaded this library and cannot get it working.

hello @ariveiene did you solve your problem because i have the same issue due to the same library ?