Problem with compiling tensorflow-lite on 5.15.71-2.2.0 release

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with compiling tensorflow-lite on 5.15.71-2.2.0 release

Jump to solution
1,914 Views
tomasz_zyjewski
Contributor III

We are trying to compile image using tensorflow-lite provided in meta-imx layer. We do not have any
custom changes/bbappends

Spoiler
sources$ find . -name tensorflow-lite*
./meta-imx/meta-ml/recipes-libraries/tensorflow-lite
./meta-imx/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite-host-tools_2.9.1.bb
./meta-imx/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite-2.9.1.inc
./meta-imx/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite
./meta-imx/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite/tensorflow-lite.pc.in
./meta-imx/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite_2.%.bbappend
./meta-imx/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite_2.9.1.bb
./meta-imx/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite-vx-delegate
./meta-imx/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite-vx-delegate_2.9.1.bb



The machine is based on imx8mm but I do not think that the problem that we have is connected somehow to machine as the error log is

Spoiler
per.dir/python/interpreter_wrapper/interpreter_wrapper_pybind11.cc.o.d -o CMakeFiles/_pywrap_tensorflow_interpreter_wrapper.dir/python/interpreter_wrapper/interpreter_wrapper_pybind11.cc.o -c /work/build-wayland
/tmp/work/armv8a-poky-linux/tensorflow-lite/2.9.1-r0/git/tensorflow/lite/python/interpreter_wrapper/interpreter_wrapper_pybind11.cc
| /work/build-wayland/tmp/work/armv8a-poky-linux/tensorflow-lite/2.9.1-r0/git/tensorflow/lite/python/interpreter_wrapper/interpreter_wrapper_pybind11.cc:16:10: fatal error: pybind11/functional.h: No such file or
directory
| 16 | #include "pybind11/functional.h"
(...)
| In file included from /work/build-wayland/tmp/work/armv8a-poky-linux/tensorflow-lite/2.9.1-r0/git/tensorflow/lite/python/interpreter_wrapper/interpreter_wrapper.cc:15:
| /work/build-wayland/tmp/work/armv8a-poky-linux/tensorflow-lite/2.9.1-r0/git/tensorflow/lite/python/interpreter_wrapper/interpreter_wrapper.h:28:10: fatal error: Python.h: No such file or directory
| 28 | #include <Python.h>
| | ^~~~~~~~~~
| compilation terminated.
| ninja: build stopped: subcommand failed.
| WARNING: exit code 1 from a shell command.
ERROR: Task (/work/sources/meta-imx/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite_2.9.1.bb:do_compile) failed with exit code '1'



Are we missing something or the recipe is broken in that release and we should use different version?

0 Kudos
Reply
1 Solution
1,794 Views
tomasz_zyjewski
Contributor III

Hello @Sanket_Parekh 

finally we were able to compile the tensorflow-lite recipe. What we need was

DEPENDS += " \
python3-pybind11 \
python3-numpy \
"

PYBIND11_INCLUDE = "${PYTHON_INCLUDE_DIR}/pybind11"
NUMPY_INCLUDE = "${PKG_CONFIG_SYSROOT_DIR}/${PYTHON_SITEPACKAGES_DIR}/numpy/core/include"

OECMAKE_C_FLAGS += "-I${PYTHON_INCLUDE_DIR} -I${PYBIND11_IN} -I${NUMPY_INCLUDE}"
OECMAKE_CXX_FLAGS += "-I${PYTHON_INCLUDE_DIR} -I${PYBIND11_INCLUDE} -I${NUMPY_INCLUDE}"

added as bbappend. Should we push that to meta-imx as a fix?

View solution in original post

0 Kudos
Reply
9 Replies
1,884 Views
tomasz_zyjewski
Contributor III

The problem seems to be with pip package, changing recipe with following diff allows to build the recipe

diff --git a/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite_2.9.1.bb b/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite_2.9.1.bb
index 9b091b95513e..e54c58dff71c 100644
--- a/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite_2.9.1.bb
+++ b/meta-ml/recipes-libraries/tensorflow-lite/tensorflow-lite_2.9.1.bb
@@ -57,8 +57,6 @@ do_configure:prepend() {

do_compile:append () {
# build pip package
- cd ${B}
- CI_BUILD_PYTHON=${PYTHON} BUILD_NUM_JOBS=8 ${S}/tensorflow/lite/tools/pip_package/build_pip_package_with_cmake2.sh ${TARGET_ARCH}
}

do_install() {
@@ -100,10 +98,6 @@ do_install() {
cp ${WORKDIR}/mobilenet_*.tflite ${D}${bindir}/${PN}-${PV}/examples

# Install pip package
- install -d ${D}/${PYTHON_SITEPACKAGES_DIR}
- ${STAGING_BINDIR_NATIVE}/pip3 install --disable-pip-version-check -vvv --platform linux_${TARGET_ARCH} \
- -t ${D}/${PYTHON_SITEPACKAGES_DIR} --no-cache-dir --no-deps \
- ${B}/tflite_pip/dist/tflite_runtime-*.whl
}

0 Kudos
Reply
1,857 Views
Sanket_Parekh
NXP TechSupport
NXP TechSupport

Hello @tomasz_zyjewski ,

I hope you are doing well.

Compiling tensorflow-lite requires three steps: fetching packages, configuring the environment, and compiling code.
If any files are not successfully downloaded during the environment configuration, an error will be reported, and the compilation will be terminated.

It looks like missing installation of pybind11 package.
One can do a proper pybind installation.

Pip doesn't give you the cmake files. The simplest solution is to check out the pybind11 source and include it with add_directory(pybind11)

Make sure that you have correctly installed the development package for Python. Use your package manager to install them system-wide.

Thanks & Regards,

Sanket Parekh

0 Kudos
Reply
1,849 Views
tomasz_zyjewski
Contributor III

Hello @Sanket_Parekh

first of all thank you for your reply.

As I mentioned in the post topic I am using NXP BSP release 5.15.71-2.2.0 and as you can see in my message, there are information about using meta-imx so I try to build tensorflow-lite using Yocto.

You mentioned the need of pybind11 package so If I understand correctly, the python-pybind11 should be in recipe DEPENDS right? Looks like the recipe missing it, as it only has the native version [1]. We tried to add that and I think it helps with the pybind11 header missing, but it does not resolve the problem with the `Python.h` one. Whats more, the python3 package is defined in DEPENDS and in recipe-sysroot we can find it under `recipe-sysroot/usr/include/python3.10/Python.h` path but the do_compile task still cannot be build correctly.

Do you have an idea how to successfully build the tensorflow-lite package using Yocto enivronment and the layers provided by NXP BSP release?

I appreciate you help and hope that we will be able to resolve this problem.

Regards
Tomasz Żyjewski

[1] https://github.com/nxp-imx/meta-imx/blob/kirkstone-5.15.71-2.2.0/meta-ml/recipes-libraries/tensorflo...

0 Kudos
Reply
1,831 Views
Sanket_Parekh
NXP TechSupport
NXP TechSupport

Hello @tomasz_zyjewski ,

I hope you are doing well.

To successfully build the TensorFlow Lite package using the yocto Project and the layers provided by NXP BSP release, you need to configure your Yocto build environment properly and include the necessary recipes and dependencies.

This issue may arise due to not having enough memory.
Make sure you have installed the required dependencies and set up the built environment according to the Yocto Project guidelines.

Thanks & Regards,

Sanket Parekh

0 Kudos
Reply
1,802 Views
tomasz_zyjewski
Contributor III

Hi @Sanket_Parekh 

unfortunately that does not help me. My workstation meets requirements set in the Yocto documentation [1]. What is strange for me is that some include files cannot be found

```

In file included from /work/build-wayland/tmp/work/armv8a-poky-linux/tensorflow-lite/2.9.1-r0/git/tensorflow/lite/python/interpreter_wrapper/python_utils.cc:16:
/work/build-wayland/tmp/work/armv8a-poky-linux/tensorflow-lite/2.9.1-r0/git/tensorflow/lite/python/interpreter_wrapper/python_utils.h:19:10: fatal error: Python.h: No such file or directory
19 | #include <Python.h>
| ^~~~~~~~~~
compilation terminated.

```

I do not think it can be caused by workstation environment but rather by environment for that given recipe, should it not be set by DEPENDS/PACKAGECONFIGS to correctly compile given package?

Also, seems that tensorflow-lite is compiled, the problem is with building pip package [2].

Regards

Tomasz Żyjewski

[1] https://docs.yoctoproject.org/4.0.10/singleindex.html#compatible-linux-distribution

[2] https://github.com/nxp-imx/meta-imx/blob/kirkstone-5.15.71-2.2.0/meta-ml/recipes-libraries/tensorflo...

0 Kudos
Reply
1,795 Views
tomasz_zyjewski
Contributor III

Hello @Sanket_Parekh 

finally we were able to compile the tensorflow-lite recipe. What we need was

DEPENDS += " \
python3-pybind11 \
python3-numpy \
"

PYBIND11_INCLUDE = "${PYTHON_INCLUDE_DIR}/pybind11"
NUMPY_INCLUDE = "${PKG_CONFIG_SYSROOT_DIR}/${PYTHON_SITEPACKAGES_DIR}/numpy/core/include"

OECMAKE_C_FLAGS += "-I${PYTHON_INCLUDE_DIR} -I${PYBIND11_IN} -I${NUMPY_INCLUDE}"
OECMAKE_CXX_FLAGS += "-I${PYTHON_INCLUDE_DIR} -I${PYBIND11_INCLUDE} -I${NUMPY_INCLUDE}"

added as bbappend. Should we push that to meta-imx as a fix?

0 Kudos
Reply
1,785 Views
Sanket_Parekh
NXP TechSupport
NXP TechSupport

Hello @tomasz_zyjewski 

->Yes, we should push that to meta-imx, it will be added as a fix.
I'm glad that the issue is resolved.
Hence, Can I close this thread now?

Thanks & Regards,

Sanket Parekh

0 Kudos
Reply
1,756 Views
tomasz_zyjewski
Contributor III

@Sanket_Parekh 

we pushed PR with needed changes to meta-imx repository on github https://github.com/nxp-imx/meta-imx/pull/16. This post can be closed as solved.

0 Kudos
Reply
1,732 Views
Sanket_Parekh
NXP TechSupport
NXP TechSupport

Hello @tomasz_zyjewski ,

I'm glad the issue is solved.
Hence closing this thread now.

Thanks & Regards,

Sanket Parekh

0 Kudos
Reply