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.
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 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.
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.
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:
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 âŚ)
Extra step 2 is to install a fortrain compiler with âsudo apt-get install gfortranâ
Step 3 is to clone the tensorflow repository as explained in step 2 of the overview page.
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.
Step 5 is step 3 of the overview page, i.e. to create and move into the tflite_build directory.
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)
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â.
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.
First make sure docker is installed and working in the Ubuntu 20.04 environment(google for itâŚ)
Then within Ubuntu 20.04
Install cmake as described above.
Install gfortran as described above
Clone the tensorflow repository as described above
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.
Execute the command âcd tensorflow_srcâ to change from your home directory to the tensorflow_src directory.
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
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.
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.