Install TensorFlow 2 Lite on Raspberry Pi 4 - Q-engineering
Go to content
TensorFlow Lite on Raspberry Pi

Install TensorFlow Lite 2.4.0 on Raspberry Pi 4

64-OS TensorFlow Lite
Last updated: July 1, 2021


TensorFlow Lite will be installed on your Raspberry Pi 4 with a 32-bit operating system, along with some examples. TensorFlow evolves over time. Models generated in an older version of TensorFlow may have compatibility issues with a newer version of TensorFlow Lite. Or vice versa. This manual describes the latest version of TensorFlow Lite. You can always install an older version by changing the version number in the download command. For example, $ wget -O, will download version 2.2.1 on your Raspberry Pi.


If you want to run the TensorFlow Lite examples we provide, please make sure you have OpenCV 4.5 installed on your Raspberry Pi according to our guide. Besides OpenCV, you also needed Code::Blocks installed. It would be comforting if you have already run our first C++ example, James.mp4, on your Pi.

Install TensorFlow Lite.

To build a very fast deep learning application, we need to install the C++ API libraries. The procedure is very simple. Just copy the GitHub repository and run two scripts. The commands are listed below.
# the tools needed
$ sudo apt-get install cmake curl
# download the latest TensorFlow version (2.4.0)
$ wget -O
# unpack and give the folder a convenient name
$ unzip
$ mv tensorflow-2.4.0 tensorflow
$ cd tensorflow
# get the dependencies
$ ./tensorflow/lite/tools/make/
# run the C++ installation (± 25 min)
$ ./tensorflow/lite/tools/make/
When everything is done, you end up with a screen like this.

TensorFlow Lite Rdy

The TensorFlow Lite flat buffers are also needed. Please use the following commands.
# install the flatbuffers
$ cd ~/tensorflow/tensorflow/lite/tools/make/downloads/flatbuffers
$ mkdir build
$ cd build
$ cmake ..
$ make -j4
$ sudo make install
$ sudo ldconfig
# clean up
$ cd ~
$ rm
If everything went well, you should have the two libraries and two folders with header files as shown in the slide show.
As of version 2.3.0, Tensorflow Lite uses dynamic linking. At runtime libraries are copied to RAM and pointers are relocated before TF Lite can run. This strategy gives greater flexibility. It all means that TensorFlow Lite now requires glibc 2.28 or higher to run. From now on, link the libdl library when building your application, otherwise, you get undefined reference to symbol dlsym@@GLIBC_2.17 linker errors. The symbolic link can be found at /lib/aarch64-linux-gnu/ on a 64-bit Linux OS, or /lib/arm-linux-gnueabihf/ on a Raspberry Pi 32-bit OS. Please see our examples on GitHub.

Install TensorFlow Lite on Raspberry Pi Zero.

The installation above includes all Raspberry Pi with an ARMv7l chip (RPi 2, RPi 3) or an ARMv8-a (RPi 4). However, the Raspberry Pi Zero ships with an ARMv6. It is possible to install TensorFlow on the Raspberry Pi Zero. Just replace the definition TARGET:=armv7l with TAGRET:=armv6 in the file Then follow the same steps as above as if you were dealing with a Raspberry Pi 4.


The compilation will take approximately 4½ hours. Remember that with only one core, clocked at 1GHz and no NEON registers, you are entering the zen zone. On our GitHub page you will find an example of TF-Lite running on a Raspberry Pi Zero, which classifies objects.

TensorFlow Lite models.

You cannot run normal TensorFlow models on the Lite software, they must be converted before use. These TensorFlow pages explain how to do this. Google has some ready-made models available on the net here.
Object detection.
Another application is detecting objects in a scene. TensorFlow Lite host one model for now. COCO SSD MobileNet v1 recognize 80 different objects. It can detect up to ten objects in a scene. On GitHub we have a C++ example of the famous Skyfall intro running on a bare Raspberry Pi 4 for 32-bit.


The most well known is, of course, the classifications of objects. Google hosts a wide range of TensorFlow Lite models, the so-called quantized models in their zoo. The models are capable of detecting 1000 different objects. All models are trained with square images. Therefore, the best results are given when your input image is also square-like. All models are supported on GitHub by our C ++ software samples for both the 32-bit and 64-bit Raspberry and Ubuntu 18.04 or 20.04 operating system.

Pose estimation.

This neural network tries to estimate a person pose in a scene. It recognizes certain key features like elbows, knees, ankles in an image. TensorFlow Lite supports two models, a single person and a multi-person version. We have only used the single person model because it gives reasonable good results when the person is centred and in full view in a square-like image. Please, find the 32-bit Raspbain C++ example at our GitHub page.

With semantic image segmentation, a neural network attempts to associate every pixel in the scene with a particular object. You could say, it tries to detect the outline of objects. Tensorflow Lite has one segmentation model capable of classifying 20 different objects. Keep in mind that only reasonable sized objects can be recognized, not a scene of a highway with lots of tiny cars. The C++ examples can be found here for 32-bit.


Frame rate.

Here, some frame rates are given of the several TensorFlow Lite models tested on a bare Raspberry Pi 4. The overclock frequencies are indications. Ubuntu always crashes above 1950 MHz when running deep learning models with the 4 cores simultaneous. Some models could run at 1950 MHz, others not higher than 1825 MHz. The 32-bit Raspbian is capable of a clock rate of 1950 MHz for all the examples. Frame rates are only based on model run time (interpreter->Invoke()). Grabbing and preprocessing of a image are not taken into account. Also noteworthy is the higher frame rate on a Raspbian for the MobileNet models compared to Ubuntu. The guide to installing Ubuntu along with OpenCV and TensorFlow Lite can be found here. Overclocking is covered here. This is the guide to install the Raspberry Pi 64-bit operating system. Installing OpenCV 4.3.0 on the 64-bit Raspberry OS is explained here.
Raspberry Pi 4
64 bit OS
1950 MHz
Raspberry Pi 4
64 bit OS
1500 MHz
Raspberry Pi 4 64 bit Ubuntu  1850 MHz
Raspberry Pi 4
64 bit Ubuntu
1500 MHz
Raspberry Pi 4
32 bit OS
1950 MHz
Raspberry Pi 4
32 bit OS
1500 MHz
MobileNet-V1 SSD
26.8 FPS
21.5 FPS24.0 FPS17.2 FPS17.0 FPS13.8 FPS
38.5 FPS32.2 FPS22.9 FPS22.5 FPS33.0 FPS22.2 FPS
45.5 FPS37 FPS19,7 FPS19,5 FPS36.2 FPS28.0 FPS
11.6 FPS
9.5 FPS10.0 FPS8.7 FPS8.9 FPS6.9 FPS
2.1 FPS
1.7 FPS2.0 FPS1.8 FPS1.6 FPS1.3 FPS
7.5 FPS6.8 FPS7.2 FPS
6.6 FPS
4.0 FPS3.6 FPS
10.3 FPS9.2 FPS9.4 FPS8.7 FPS5.0 FPS4.3 FPS

Python installation of TensorFlow Lite.

For completeness, the Pythons installation of TensorFlow Lite 2.1.0 is given here. It is only one command. There are no wheels for TensorFlow Lite version 2.2.0, 2.3.0 and 2.3.1. Python examples can be found everywhere on the net. Google has also made an example here.
$ pip3 install
Deep learning examples for Raspberry Pi
Raspberry 64 OS
Raspberry 32 OS
Raspberry and alt
Raspberry Pi 4
Jetson Nano
Back to content