Spresense SDK - Tensorflow : Flatbuffers missing
Hello I am trying to recreate Tensorflow demo called :"micro_speech" located : "tensorflow/lite/micro/examples/micro_speech/"
However during a build I am getting : "fatal error: flatbuffers/flatbuffers.h: No such file or directory"
I really don't know how to solve this issue?
Is there anyway how to import this library ?
The flatbuffers library is downloaded during the build process. Please check if you successfully downloaded the flatbuffers library while building. You can check this in the logs after running
After a successful download, the library will be here:
Thank you very much for your help.
Yes the flatbuffers library was missing, unfortunately I was not able to run make command so I manually launched flatbuffers_download.sh script which successfully downloaded this library. However problem still persists
Here is messages :
In file included from /Users/arcius/spresenseenv/usr/arm-none-eabi/include/c++/7.3.1/type_traits:35:0, from /Users/arcius/C++/Sony-Spresense/spresense/sdk/../externals/tensorflow/tensorflow-372e7eef27e03adabceb4c7ca41d366776573a73/tensorflow/lite/core/api/flatbuffer_conversions.h:24, from /Users/arcius/C++/Sony-Spresense/spresense/sdk/../externals/tensorflow/tensorflow-372e7eef27e03adabceb4c7ca41d366776573a73/tensorflow/lite/micro/micro_mutable_op_resolver.h:23, from /Users/arcius/C++/Sony-Spresense/spresense/sdk/../externals/tensorflow/tensorflow-372e7eef27e03adabceb4c7ca41d366776573a73/tensorflow/lite/micro/all_ops_resolver.h:19, from VoiceRecognition.cxx:3: /Users/arcius/spresenseenv/usr/arm-none-eabi/include/c++/7.3.1/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support \ ^~~~~ In file included from /Users/arcius/C++/Sony-Spresense/spresense/sdk/../externals/tensorflow/tensorflow-372e7eef27e03adabceb4c7ca41d366776573a73/tensorflow/lite/core/api/flatbuffer_conversions.h:28:0, from /Users/arcius/C++/Sony-Spresense/spresense/sdk/../externals/tensorflow/tensorflow-372e7eef27e03adabceb4c7ca41d366776573a73/tensorflow/lite/micro/micro_mutable_op_resolver.h:23, from /Users/arcius/C++/Sony-Spresense/spresense/sdk/../externals/tensorflow/tensorflow-372e7eef27e03adabceb4c7ca41d366776573a73/tensorflow/lite/micro/all_ops_resolver.h:19, from VoiceRecognition.cxx:3: /Users/arcius/C++/Sony-Spresense/spresense/sdk/../externals/tensorflow/tensorflow-372e7eef27e03adabceb4c7ca41d366776573a73/tensorflow/lite/schema/schema_generated.h:21:10: fatal error: flatbuffers/flatbuffers.h: No such file or directory #include "flatbuffers/flatbuffers.h"
What OS are you using?
BigSur ( Macbook M1 )
I think the problem may be that TensorFlow doesn't support building on Mac.
Could you please try to build this example on any target: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/micro/examples/hello_world
Follow the instructions from the README.
I can see ( from build logs ) that tensorflow sources are build successfully. The output builds can be found in
however when use this includes in my project :
#include "tensorflow/lite/micro/all_ops_resolver.h" #include "tensorflow/lite/micro/micro_error_reporter.h" #include "tensorflow/lite/micro/micro_interpreter.h" #include "tensorflow/lite/schema/schema_generated.h" #include "tensorflow/lite/version.h"
I am getting error mentioned above.
In SDK Config I set 'Spresense SDK' -> 'Externals' -> 'Tensorflow lite micro' to 'Y'.
Also in Makefile of my application ( command ) I set
# C++ compiler flags CXXFLAGS = -std=c++11
To avoid those
error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options. #error This file requires compiler and library support \
Is there anything that I forgot ? ( I don't think that problem is with TensorFlow and Mac ).
Since you are trying to recreate Tensorflow demo called :"micro_speech", can you try to run these commands:
spresense/sdk$ make distclean spresense/sdk$ ./tools/config.py examples/tf_example_micro_speech spresense/sdk$ make
This will allow you to build and run "micro_speech" demo on Spresense. Flash .spk, open nuttx shell and run this command:
I would like to first check if you can successfully run it. Please let me know.
Arco last edited by Arco
tf_example_micro_speech was successfully build -> flashed -> launched ( working correctly ) on my Spresense.
@Arco Thank you for your confirmation.
The problem is that the compiler doesn't have the path given where the flatbuffers library is. Even if you add it, you will encounter other errors. This is because there are two build systems. The first is NuttX which has its own implementations of standard libraries. The second is TensorFlow which uses the standard libraries from the compiler. When you try to build something with TensorFlow on NuttX then you have compatibility problems with standard libraries.
If you want to create a new application then you must include it in the TensorFlow system build. Then, in the NuttX application, call functions like in this example:
It is currently not possible to call TensorFlow functions directly from the NuttX application. This is only temporary because we are working to make it possible. This is the first SDK release that has allowed the TensorFlow examples to run on Spresense and unfortunately has some limitations.
I am sorry for the inconvenience.
@KamilTomaszewski Thank for your help I own you one
Do you think that another solutions like CircuitPython or MicroEJ would be better for using TensorFlow ?
Thank you again
@Arco You're welcome.
Unfortunately, TensorFlow is currently only supported on the NuttX SDK.
after a while I came back to this issue.
I tried to create new project inside of /spresense/examples (same as tf_examples). I was following whole structure of tf_examples from Makefile, Kconfig to creating configuration files in /spresense/sdk/examples/.
I have launched ( hlasove_povely is name of the project )
$ tools/config.py hlasove_povely
and after that
But I am getting this output :
make: *** No rule to make target `context'. Stop. make: *** [hlasove_povely_context] Error 2 make: *** [../examples/_context] Error 2 make: *** [/Users/arcius/C++/Sony-Spresense/spresense/sdk/apps/.._context] Error 2 make: *** [context_serialize] Error 2 make: *** [context] Error 2 make: *** [all] Error 2
Am I something missing thanks
Right now after calling :
the response is :
make: *** No rule to make target `preconfig'. Stop. make: *** [Kconfig] Error 2 make: *** [../examples/_preconfig] Error 2 make: *** [preconfig] Error 2 make: *** [Kconfig] Error 2 make: *** [apps_preconfig] Error 2 make: *** [olddefconfig] Error 2 Post process failed. 512 Try 'make distclean' first.
(I tried 'make distclean' but didn't help)
Do you include in your Makefile:
The error could be because it is missing.
Arco last edited by Arco
Yes I do.
-include $(TOPDIR)/Make.defs -include $(SDKDIR)/Make.defs PROGNAME = $(CONFIG_EXAMPLES_HLASOVE_POVELY_PROGNAME) PRIORITY = $(CONFIG_EXAMPLES_HLASOVE_POVELY_PRIORITY) STACKSIZE = $(CONFIG_EXAMPLES_HLASOVE_POVELY_STACKSIZE) MODULE = $(CONFIG_EXAMPLES_HLASOVE_POVELY) MAINSRC = hlasove_povely_main.c include $(APPDIR)/Application.mk
ifneq ($(CONFIG_EXAMPLES_HLASOVE_POVELY),y) CONFIGURED_APPS += hlasove_povely endif
config EXAMPLES_HLASOVE_POVELY tristate "Tensorflow Example app" default n ---help--- Enable the NuttX command line application for executing example of Tensorflow lite micro. if EXAMPLES_HLASOVE_POVELY config EXAMPLES_HLASOVE_POVELY_PROGNAME string "Program name" default "hlasove_povely" ---help--- This is the name of the program that will be use when the NSH ELF program is installed. config EXAMPLES_HLASOVE_POVELY_PRIORITY int "hlasove_povely task priority" default 100 config EXAMPLES_HLASOVE_POVELY_STACKSIZE int "hlasove_povely stack size" default 32768 endif
Could you try to create a new example using this command:
sdk$ ./tools/mkcmd.py hlasove_povely
Response is :
hlasove_povely already exists
Delete or move your old example out of sdk and create a new one using this command.