Install TensorFlow 2.4 on Raspberry 64 OS
This page will guide you through the installation of TensorFlow 2.4.0 or TensorFlow 2.4.1 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.
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.
We discuss two installations, one for Python 3 and one C++ API library. Unfortunately, there is no official pip3 wheel available for the 2.4 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.
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 (±41 for Python, ±10 for the C++ library, overclocked to 1900 MHz). With all the tedious work already done, it takes still one hour and twenty minutes to install TensorFlow 2.4 on your Raspberry 64-bit OS. For the diehards, the complete procedure is covered later in this manual.
TensorFlow 2.4 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.4.x-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.