How to replace person_detection with a custom network

Can you provide me a guide or some hints to replace the person detection in FW? I would like to use my own custom .tflite network.
I saw that I should work on the files in src/libtf/ folder, but I am not sure how.

Thank you.


You just need to turn your .tflite file into a C source/header file using xxd(1): make hexdump/do reverse - Linux man page, hexdump - How to dump a binary file as a C/C++ string literal? - Unix & Linux Stack Exchange.

Once you do that, edit the Make file to include your new c file and then the top level make file to include the new .o object, then finally, edit py_tf.c in src/omv/py to reference the new model and edit the string name of the network.

Hi @kwagyeman. It looks like the default person_detection model is a pre-compiled library located at /src/lib/libtf/cortex-m7/libtf_person_detect_model_data.a. I’m following the README which provides a long list of CXX compiler flags to use when compiling the C source/hreader file generated by xdd.

I did this for my own .tflite file, compiled it with arm-none-eabi-gcc and the CXX flags in the README. When I run make, I’m getting the following error:

/home/USER/src/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: cannot use executable file '/home/USER/src/openmv/src/lib/libtf/cortex-m7/libtf_custom_model_data.a' as input to a link
collect2: error: ld returned 1 exit status
make: *** [omv/ports/stm32/ firmware] Error 1

Should I ignore the README instructions and just update the Makefile as you suggested? If so, can you provide a bit more guidance on how to include this in my Makefile? It’s unclear to me how the top-level Makefile uses TENSORFLOW_DIR=lib/libtf during compilation.


Hi, you should just change the name in the py_tf.c file to use your custom header/c file that you generated using xdd.

The library file for person detection will not be included in the final image if nothing references it.

OK, I decided to just end up placing the custom header and .c files in src/omv/modules/ instead of trying to link it from src/lib.

Now I just need to figure out how to pare down unnecessary libraries to make room for my slighty oversize model…

See the board config folder. You can disable stuff.

Thanks. I did but I believe my model is too large (~1000 kB). Even if I disable nearly all of the IMLIB features, I can’t get the firmware size down to fit the model.

Do you have any other recommendations (other than shrinking my model)? It looks like the OS / micropython requires at least 1.1 MB of flash memory, even with most of the features disabled.

You probably should shrink the model.