tensorflow / tflite-micro

Infrastructure to enable deployment of ML models to low-power resource-constrained embedded targets (including microcontrollers and digital signal processors).
Apache License 2.0
1.85k stars 805 forks source link

create_tflm_tree fails #2534

Closed kraiskil closed 6 months ago

kraiskil commented 6 months ago

Hello.

I am trying to make a project using TFLM, using the tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py script, but I can't get it to work. I am new to TFLM, so it might be just that I am not reading the correct documentation. Please stop reading at the first error I make :)

What I tried was to follow the instructions in tensorflow/lite/micro/docs/new_platform_support.md to create the sources for libtflm.a I took a clean clone of TFLM, and then run the script as instructed in the documentation:

$ git clone https://github.com/tensorflow/tflite-micro.git
$ cd tflite-micro
$ git submodule update --init --recursive
$ mkdir ../tflm_project
$ python3 tensorflow/lite/micro/tools/project_generation/create_tflm_tree.py -e hello_world ../tflm_project/

This fails with

[...]
FileNotFoundError: [Errno 2] No such file or directory: 'tensorflow/lite/micro/tools/make/downloads/flatbuffers/include/flatbuffers/code_generator.h'

There does exist a code_generators.h in that directory though (difference is the trailing 's' in the filename).

Reading other documentation, I tried to build TFLM (in source tree) - maybe that is a pre-requisit since it nudges me a bit forward?:

$ make -f tensorflow/lite/micro/tools/make/Makefile 
tensorflow/lite/micro/tools/make/downloads/flatbuffers already exists, skipping the download.
[...]
./tensorflow/lite/schema/schema_generated.h:12:46: error: static assertion failed: Non-compatible flatbuffers version included
   12 |               FLATBUFFERS_VERSION_MINOR == 5 &&

Seems like the build expects Flatbuffers 2.5, but what was downloaded looks like 2.0.6.

Am I doing something completely wrong, or would it make sense to try to debug my steps further. I'm happy to try to fix this, but I would like to know I am on the right track at least.

thank you in advance, kalle

rascani commented 6 months ago

$ git submodule update --init --recursive FYI, TFLM does not use submodules, so this is not needed.

Seems like the build expects Flatbuffers 2.5, but what was downloaded looks like 2.0.6.

We actually expect v23.5.26, which is the version we download as part of the make build (which will be invoked during create_tflm_tree.py): https://github.com/tensorflow/tflite-micro/blob/main/tensorflow/lite/micro/tools/make/flatbuffers_download.sh#L57

I think you're generally on the right track, and I'm not sure how you're winding up with a different flatbuffers version. The create_tflm_tree.py is tested as part of this script. You might want to take a look and see if there's something you're doing differently.

kraiskil commented 6 months ago

Thank you rascani for confirming.

Turns out this was a compound of a few mistakes on my part. That I could replicate on two different systems, which led me on the wrong debugging path.

In case someone has the same problem in the future: Original problem was, that after a git pull, the downloaded flatbuffers was not re-downloaded. A git clean -xdf was not enough to clean up. Only with a git clean -xdff was the downloaded flatbuffers removed.

I tried to re-create the problem with a clean clone, as in my first message. But I mixed up the two clone directories, and by mistake I didn't actually try the fresh clone as I claimed. The fresh clone, of course, works too.