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.86k stars 806 forks source link

hello_world_model_data.h - a mysteriously appearing file? #631

Closed ICTSoEasy closed 2 years ago

ICTSoEasy commented 2 years ago

Where does tensorflow/lite/micro/examples/hello_world/hello_world_model_data.h come from?

I've been from pillar to post trying to get this to run on a pico - even the TinyML book has it just appearing!

Finfalter commented 2 years ago

Run the tests on your development machine

make -f tensorflow/lite/micro/tools/make/Makefile third_party_downloads
make -f tensorflow/lite/micro/tools/make/Makefile test_hello_world_test

With these (the first line, actually) _hello_world_model_data.cc and hello_world_model_data.h_ are generated during the built. They are stored in

tensorflow/lite/micro/tools/make/gen/linux_x86_64_default/genfiles/tensorflow/lite/micro/examples/hello_world

This is at least the case for a 64-bit x86 Linux machine.

In tensorflow/lite/micro/tools/make/Makefile, lines 233 ff., there are some hints where the generated files are stored in a general case:

# Where compiled objects are stored.
GENDIR := $(MAKEFILE_DIR)/gen/$(TARGET)_$(TARGET_ARCH)_$(BUILD_TYPE)/
# [..]
GENERATED_SRCS_DIR := $(GENDIR)genfiles/

I absolutely agree that the matter is intransparent (even after having read the book!). Perhaps, the docs could be improved.

njeffrie commented 2 years ago

@Finfalter is exactly correct.

We have been trying to move from examples with model_data.h and model_data.cc to a single model.tflite, and generate the cc and header during the build. If you're curious about the generation process, we use this script to generate the cc and header files.

I agree w.r.t. improving documentation - I will look at including a section about data generation in our README.