- Edited
Hi,
I'm trying to use tflite in a Bela project. I built tflite for Bela using rodrigodzf's repo: https://github.com/rodrigodzf/bela-tflite. I copied the folder into 'Bela/libraries/' so that the folder structure now looks like this:
/root/Bela/libraries/tensorflow-lite
-- build/
-- tensorflow/lite/ *.cc, *.h files
The minimal example I'm trying to run is an adapted version from https://stackoverflow.com/questions/56837288/tensorflow-lite-c-api-example-for-inference, located in /root/Bela/projects/tf-test
:
#include <Bela.h>
#include "tensorflow/lite/interpreter.h"
#include "tensorflow/lite/kernels/register.h"
#include "tensorflow/lite/model.h"
#include "tensorflow/lite/tools/gen_op_registration.h"
bool setup(BelaContext *context, void *userData)
{
std::unique_ptr<tflite::FlatBufferModel> model = tflite::FlatBufferModel::BuildFromFile("linear.tflite");
return true;
}
void render(BelaContext *context, void *userData)
{
}
void cleanup(BelaContext *context, void *userData)
{
}
and the command I am using to build this (following these instructions https://blog.bela.io/using-an-external-library-with-bela/)
make -C /root/Bela PROJECT=tf-test CPPFLAGS="-I/root/Bela/libraries/tensorflow-lite/tensorflow/lite" LDFLAGS="-L/root/Bela/libraries/tensorflow-lite/build" LDLIBS="-l/root/Bela/libraries/tensorflow-lite/build/libtensorflow-lite.a"
The compiler doesn't seem to find the library files since I get this error:
/root/Bela/projects/tf-test/render.cpp:2:10: fatal error: 'tensorflow/lite/interpreter.h' file not found
#include "tensorflow/lite/interpreter.h"
^
I don't know if the issue has to do with the fact that apparently tflite needs to have an add_subdirectory command in the cmake file, as said in the tflite documentation https://www.tensorflow.org/lite/guide/build_cmake and in this comment https://stackoverflow.com/a/70261676. Any ideas on how to do this? Is there any way to have a custom CMakeLists for a Bela project? Or am I missing any basic linking libraries commands?
Thank you!!
Edit: I changed the make command semicolons following this: https://forum.bela.io/d/2223-compiling-with-external-libraries/2
Edit2: there's this FindTFLite.cmake file https://github.com/rodrigodzf/DeepLearningForBela/blob/main/cmake/Modules/FindTfLite.cmake but I'm not very sure how to add it to the Bela project cmake
Edit3: I also tried copying libtensorflow-lite.a
to usr/local/lib
and the contents of /root/Bela/libraries/tensorflow-lite/tensorflow/lite
(all of the *.h
and *.cpp
files) into usr/local/include/libtensorflow-lite
. With this, running the command make -C /root/Bela PROJECT=tf-test LDLIBS="-llibtensorflow-lite"
still gives the same error