Install TensorFlow 2.6 on Raspberry 64 OS
Last updated: December 30, 2021
This page will guide you through the installation of TensorFlow 2.6.0, 2.5.1 or 2.5.0 on a Raspberry Pi 4 with a 64-bit operating system.
TensorFlow is a large software library specially developed for deep learning. It consumes a vast amount of resources. You can execute TensorFlow on a Raspberry Pi 4, but don't expect miracles. It can run your models, if not too complex, but it will not be able to train new models. Nor can it perform the so-called transfer learning. In addition to running your pre-built deep learning models, you may use the library to convert so-called frozen TensorFlow models to TensorFlow Lite flat buffer models.
If you only want to get some impression of deep learning, please consider installing TensorFlow Lite. It is much faster and uses far fewer recourses, as being designed for small computers like a Raspberry Pi. There are many ready build models you can use. See our installation guide for the 64-bit Raspberry here.
If you have Ubuntu on your Raspberry Pi, please follow this link for the installation of TensorFlow 2.5 on Ubuntu 20.04.
TensorFlow continues to grow. Each new release requires more resources, supporting software and libraries. It increasingly puts a heavy burden on your Raspberry Pi. It explains why the latest versions don't work well on 'old' Raspberry Pis with an 'outdated' operating system.
On the other hand, it is not advisable to install a very old TensorFlow version on the latest Bullseye. You will be forced to downgrade some system libraries, which will prevent other software from working. The motto here: "Go with the Flow".
Below is an overview. A green checkmark indicates a wheel is available. An empty green box means there is no wheel, but installation is still possible. A grey box specifies hardware or software limitations that do not allow a 'normal' installation.
|System||TF 2.0||TF 2.1||TF 2.2|
|TF 2.5||TF 2.6||TF 2.7|
|Raspberry Pi 32-bit Buster|
Raspberry Pi 64-bit Buster
|Raspberry Pi Ubuntu 18.04|
|Raspberry Pi Ubuntu 20.04|
Raspberry Pi 64-bit Bullseye
|Jetson Nano JetPack 4.6|
Regularly, we get the question if we have an SD image of a Raspberry Pi 4 with pre-installed frameworks and deep-learning examples.
We are happy to comply with this request. Please, find a complete working Raspberry Pi 4 dedicated to deep learning on our GitHub page. Download the zip file from our GDrive site, unzip and flash the image on a 16 GB SD-card, and enjoy!
We only have a guide for the Raspberry Pi 64-bit operating system. As the massive TensorFlow evolves, building it on a simple 32-bit machine is getting more and more difficult. Many tricks and workarounds were required to compile bazel 3.1.0 and TensorFlow 2.4. Besides, most of our visitors today use a 64-bit operating system on their Raspberry Pi for their deep learning models because it is faster and more robust.
The same goes for Ubuntu 18.04. TensorFlow 2.5 relies on h5py version 3.1.0, which is very difficult to install on an aarch64 running Python 3.6, such as Ubuntu 18.04 on a Raspberry Pi.
We discuss two installations, one for Python 3 and one C++ API library. Unfortunately, there is no official aarch64 pip3 wheel available for the 2.6 or 2.5 versions. However, we created our wheels with Bazel and put them on GitHub for your convenience.
The last part of this guide discuss the installation of Keras.
Ever since numpy upgrades to version 1.20, TensorFlow is experiencing issues with this latest version. It became a real struggle to port TensorFlow to numpy 1.20. Now, with TensorFlow version 2.6.0, it seems to have finally succeeded. However, there are still a few reports of problems. To be on the safe side, we're still using numpy version 1.19.5 now, so you're guaranteed everything will work properly. With the next release, we will build the wheel with the latest numpy version 1.20.
It means that you should check your numpy version first and change it if necessary before installing the other software. Especially h5py needs to be built with the correct numpy version to work with TensorFlow. It also means that other software installed in the future should not upgrade numpy. By the way, this is no different from the previous TensorFlow versions.
Please check your operating system before installing TensorFlow on your Raspberry 64-bit OS. Run the command uname -a and verify your version with the screen dump below.
You also need to check your C++ compiler version with the command gcc -v. It must also be an aarch64-linux-gnu version, as shown in the screenshot. If you have a 64-bit operating system, but your gcc version is different from the one given above, reinstall the whole operating system with the latest version. The guide is found here: Install 64 bit OS on Raspberry Pi 4. You must have a 64-bit C ++ compiler as we are going to build libraries. Even if you use Python wheels, gcc is called behind the curtains.
Also, note the zram swap size of more than 3 Gbyte after installation according to our instructions.
TensorFlow is installed by a Google software installer called Bazel. In the end, Bazel generates a wheel to install the TensorFlow Python version or a tarball when it comes to installing the C++ version. Both methods are well known to Raspberry Pi users. We have posted the Bazel outcomes on our GitHub page. Feel free to use these shortcuts. The whole TensorFlow installation procedure from start to end takes many hours (±56 for Python, ±10 for the C++ library). With all the tedious work already done, it takes still one hour and twenty minutes to install TensorFlow 2.6 or 2.5 on your Raspberry 64-bit OS. For the diehards, the complete procedure is covered later in this manual.
TensorFlow 2.6 for Python 3.
The whole shortcut procedure is found below. The wheel was too large to store at GitHub, so Google drive is used. Please make sure you have latest pip3 and python3 version installed, otherwise, pip may come with the message ".whl is not a supported wheel on this platform".
Check your Python3 version. Each version needs a unique wheel. Currently, the Raspberry Pi 64-bit operating system uses Python 3.7.3. So you need to download tensorflow-2.6.0-cp37-cp37m-linux_aarch64.whl. Undoubtedly, the Python version will upgrade over time and you will need a different wheel. See out GitHub page for all the wheels.