Instructions for Cmake on Raspberry Pi Zero are inaccurate

Thanks for trying and confirming.

Did you use Ubuntu version 16? I used version 20 in the WSL. Maybe I should downgrade?

Was the p0 wheel produced within the cf_ti.pi-python39 docker or within the host?

Did you get the same error messages in the cmake part as I posted, like the message about clang?

As I’ve used the tensorflow/tools/ci_build/ci_build.sh method thus script, in the linux host, will run the compilation in docker to produce the wheel image.

No error just some GCC warnings on compilation.

I tried running the python wheel approach in Ubuntu 16.04 on WSl… resulted in exactly the same problem.

You have mentioned different problems in the thread. What do you have in this specific case?

same problem as in Ubuntu 20, i.e. after 98% cmake it reports an error:
ERRO[0169] error waiting for container: invalid character ‘u’ looking for beginning of value

I am now going to install Cmake 3.20 within Ubuntu 16.04 to try the Cmake approach (without piwheel). The base version was 3.5.1 and it needs 3.16 as minimum. Within Ubuntu 20.04 it was already Cmake version 3.16.3

Update: cmake version 3.20 also does not make any difference, same error as above when using docker and internal compiler errors when running cmake build directly on Ubuntu 16.04

I give up

I don’t know if It is a specific WSL Docker bug as with Docker for MAC:

Have you tried to set ${BUILD_NUM_JOBS} to a fixed value?

1 Like

I now tried it with setting the number of processor to 4 and … drumbeat … IT WORKED !!!
It produced tflite_runtime-2.8.0-cp39-cp39-linux_armv6l.whl
I did not transport it yet to the Raspberry Pi.

I think previously the script tried to use 8 processors.

Thank you so much for your assistance.

I think it was more than 8 as without the value I saw too much parallel jobs running at 98% exhausting host resources (mainly memory/swap).

Please open an issue on Github about this.

I will do.

Just to add: also running the cross-compilation for ARM with Cmake (step 5 and 6 of the Build with Cmake overview page) works correctly if I add the number of processors/cores to the cmake build command.

1 Like

So to summarize the “site feedback” of this thread.

In order to run the cross compilation for ARM for the Raspberry Pi Zero (with Bullseye OS and Python 3.9), using Ubuntu 20.04 within WSL2 the following changes/clarifications need to be made to the site instructions:

  1. Step 1 is to install the cmake tool as explained in step 1 on the overview page. On Ubuntu 20.04 this will install Cmake version 3.16, which is fine. On Ubuntu 16.04 this will install Cmake 3.5, which is not good enough, so a manual installation of Cmake is required (google for it …)
  2. Extra step 2 is to install a fortrain compiler with “sudo apt-get install gfortran”
  3. Step 3 is to clone the tensorflow repository as explained in step 2 of the overview page.
  4. Step 4 is to download the toolchain as explained on the “cross compilation for ARM” page. However as a second line in these toolchain instructions the command "mkdir -p ${HOME}/toolchains" needs to be added.
  5. Step 5 is step 3 of the overview page, i.e. to create and move into the tflite_build directory.
  6. Step 6 is to run Cmake as described on the “Cross compliation for ARM” page. However, since this is run form the tflite_build directory, the path “…/tensorflow/lite/” in the Cmake command needs to be changed into "…/tensorflow_src/tensorflow/lite/ " (with 2 dots, not three as shown by this forum editor)
  7. Step 7 is step 5 of the overview page, i.e. run the cmake build. However the number of processors/cores of the host machine needs to be added to the command. So for an i5 processor with 4 cores the command would be “cmake --build . -j 4”.
  8. Optional step 8 is step 6 of the overview page, also with the number of cores added to the command.

The above generates a library called libtensorflow-lite.a. See the overview page step 5 for further explanation of next steps.

Similarly, in order to use the Build Python Wheel approach instead on Ubuntu 20.04 within WSL:

  1. First make sure docker is installed and working in the Ubuntu 20.04 environment(google for it…)

Then within Ubuntu 20.04

  1. Install cmake as described above.
  2. Install gfortran as described above
  3. Clone the tensorflow repository as described above
  4. Adapt the file “tensorflow_src/tensorflow/lite/tools/pip_package/build_pip_package_with_cmake.sh” with your favourite text editor to change line 123. On that line replace “${BUILD_NUM_JOBS}” with the number of processors/cores of your host system, for example 4 in my case. So it would now read “cmake --build . --verbose -j 4 -t _pywrap_tensorflow_interpreter_wrapper” instead. Save the file.
  5. Execute the command “cd tensorflow_src” to change from your home directory to the tensorflow_src directory.
  6. Execute the command " tensorflow/tools/ci_build/ci_build.sh PI-PYTHON39 tensorflow/lite/tools/pip_package/build_pip_package_with_cmake.sh rpi0". (see page build Python Wheel for instructions for any other Raspberry Pi or Python version)

This command will create a docker container called tf_ci.pi-python39 and will use that docker container to create a Python wheel called “/workspace/tensorflow/lite/tools/pip_package/gen/tflite_pip/python3.9/dist/tflite_runtime-2.8.0-cp39-cp39-linux_armv6l.whl” located within the Ubuntu 20.04 environment (not within the container). Note “workspace” in this case should be replaced with “tensorflow_src” if starting from the home directory.

That python wheel can then be installed on the Raspberry Pi Zero.

Hi Willem, thanx for summarizing the issue. I too was interested to run tensorflow lite in raspberry pi zero. Installed the packet and got “illegal instruction” in python script. After that I tried three days to compile and get tensorflow lite to pi zero without success. I agree that instructions found from this site are not very good. With some modification I was able to cross-compile tensorflow lite library, but was never able to create wheel package. Then I lost the interest, after all installing tf-lite should have been just one pip command.

Maybe I try your instructions even though I’m not familiar with Docker. But if tf-lite is meant to be something very easy to start with, the original pip packet should be fixed. However, I’m glad that you finally made it Willem :slightly_smiling_face:

Hi Tero,

Don’t let your lack of knowledge of docker scare you from trying the Python wheel approach. I had zero knowlegde about docker when I started this (except for the concept as such) and actually you don’t need any knowledge about docker for the python wheel approach. The only thing to do is to make sure docker is installed and working. The tensorflow build steps for the Python wheel will make use of docker but the end result (the whl file) is available outside docker in the standard Ubuntu environment.

So why is nobody using this site feedback to correct the errors on the site? (see summary dec 21)

Can you propose a DOC PR?

You can follow this guide:

I don’t know what you mean. What are you proposing? What is a DOC PR?

I already specified all errors and listed the missing information in my summary of Dec 21 in this thread above. That should be enough for someone in charge of the maintenance of this site to make the required corrections.

What I mean is that as we are an open source community/project other then a product you could propose a change with a PullRequest on GitHub to adapt or fix the documentation directly without waiting someone else to fix it if you want to accelerate.

When your PR is reviewed and accepted it will be rendered automatically on the website.

Check:

Done. Hope I have done it correctly. My first time.

2 Likes

Thanks, just for reference it is:

Working on Raspberrypi Zero package: https://github.com/jhuss/tflite_runtime_rpi0/releases/download/v2.9.0/tflite_runtime-2.9.0-cp39-cp39-linux_armv6l.whl

1 Like