# Running TensorFlow Lite Object Recognition on the Raspberry Pi 4 or Pi 5

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/080/374/medium800/camera_guide_image.jpg?1567552337)

Want to up your robotics game and give it the ability to detect objects? Maybe implement a security camera that can see and identify certain items? Now that the Raspberry Pi is fast enough to do machine learning, adding these features is fairly straightforward.

This guide will show you the steps to get TensorFlow 2 installed on your Raspberry Pi 4 or 5 and perform some object detection using the TensorFlow Lite Python Interpreter, which is faster than the full TensorFlow interpreter.

There are two main setup paths to choose from. The first option is with a PiTFT if you want to have a larger display. The second option is with the BrainCraft HAT, which has a built-in display and audio along several other components such as DotStar LEDs, a Joystick, and ports.

## Raspberry Pi 4 or 5 Computer & Camera
To start with, you will need a Raspberry Pi 4 or 5. Since TensorFlow object detection is processing intensive, you should use at least the 4GB model.

Warning: 

### Raspberry Pi 5 - 4 GB RAM

[Raspberry Pi 5 - 4 GB RAM](https://www.adafruit.com/product/5812)
The Raspberry Pi 5&nbsp;is the newest Raspberry Pi computer, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 5 better than the 4? How about a&nbsp;_faster_ processor, USB 3.0 ports, and an updated Gigabit Ethernet chip with PoE...

In Stock
[Buy Now](https://www.adafruit.com/product/5812)
[Related Guides to the Product](https://learn.adafruit.com/products/5812/guides)
![Angled shot of green Raspberry Pi 5 microcontroller.](https://cdn-shop.adafruit.com/640x480/5812-01.jpg)

### Raspberry Pi 4 Model B - 4 GB RAM

[Raspberry Pi 4 Model B - 4 GB RAM](https://www.adafruit.com/product/4296)
The Raspberry Pi 4 Model B is the newest Raspberry Pi computer made, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 4 better than the 3? How about a&nbsp;_faster_ processor, USB 3.0 ports, and updated Gigabit Ethernet chip with...

In Stock
[Buy Now](https://www.adafruit.com/product/4296)
[Related Guides to the Product](https://learn.adafruit.com/products/4296/guides)
![Angled shot of Raspberry Pi 4](https://cdn-shop.adafruit.com/640x480/4296-11.jpg)

You will need a camera for the Raspberry Pi to see with.

### Raspberry Pi Camera Module 3 Standard

[Raspberry Pi Camera Module 3 Standard](https://www.adafruit.com/product/5657)
Raspberry Pi Camera Module 3 is a compact camera from Raspberry Pi. Featuring autofocus and a 12-megapixel sensor, and supported by Raspberry Pi's Picamera2 Python library, Camera Module 3 gives you excellent image quality with precise control.

**Camera Module 3 Standard...**

In Stock
[Buy Now](https://www.adafruit.com/product/5657)
[Related Guides to the Product](https://learn.adafruit.com/products/5657/guides)
![Angled shot of camera module assembled onto a Raspberry Pi 4 computer.](https://cdn-shop.adafruit.com/640x480/5657-04.jpg)

### Raspberry Pi Camera Board v2 - 8 Megapixels

[Raspberry Pi Camera Board v2 - 8 Megapixels](https://www.adafruit.com/product/3099)
Snap, snap! The Camera v2 is the new official camera board released by the Raspberry Pi Foundation!

The **Raspberry Pi Camera Board v2** is a high quality 8 megapixel Sony IMX219 image sensor custom designed add-on board for Raspberry Pi, featuring a fixed focus lens....

In Stock
[Buy Now](https://www.adafruit.com/product/3099)
[Related Guides to the Product](https://learn.adafruit.com/products/3099/guides)
![Angled shot of Raspberry Pi Camera Board v2 - 8 Megapixels connected to a flex cable and a Raspberry Pi.](https://cdn-shop.adafruit.com/640x480/3099-02.jpg)

For the Raspberry Pi 5, you will also need a camera cable, which has a different size than the one that comes with the camera.

### Raspberry Pi 5 FPC Camera Cable - 22-pin 0.5mm to 15-pin 1mm

[Raspberry Pi 5 FPC Camera Cable - 22-pin 0.5mm to 15-pin 1mm](https://www.adafruit.com/product/5818)
This&nbsp; **200mm&nbsp;long** &nbsp; **camera cable** &nbsp;is specifically designed to work with the&nbsp; **Raspberry Pi 5** &nbsp;series.&nbsp;Just plug it into your Pi 5's camera port and then the other end into one of the official&nbsp;<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/5818)
[Related Guides to the Product](https://learn.adafruit.com/products/5818/guides)
![Angled shot of Raspberry Pi 5 connected to HQ camera.](https://cdn-shop.adafruit.com/640x480/5818-04.jpg)

## All-in One BrainCraft HAT

If you want to get a HAT that has everything you need besides the camera including display, sound, and cooling, you'll want to pick up the BrainCraft HAT.

### Adafruit BrainCraft HAT - Machine Learning for Raspberry Pi 4

[Adafruit BrainCraft HAT - Machine Learning for Raspberry Pi 4](https://www.adafruit.com/product/4374)
The idea behind the BrainCraft HAT is that you’d be able to “craft brains” for Machine Learning on the EDGE, with Microcontrollers & Microcomputers. On&nbsp;ASK AN ENGINEER, our founder & engineer chatted with&nbsp;Pete Warden, the technical lead of the mobile,...

In Stock
[Buy Now](https://www.adafruit.com/product/4374)
[Related Guides to the Product](https://learn.adafruit.com/products/4374/guides)
![Video of a white hand hovering a coffe mug over a Adafruit BrainCraft HAT thats connected to a Raspberry Pi 4. Display detects that its a coffee mug. ](https://cdn-shop.adafruit.com/product-videos/640x480/4374-00.jpg)

## Display Output

You will also need a display so you can see what it's detecting. You can use any of our displays with the Raspberry Pi, but the 3.5" display is Adafruit's biggest.

### PiTFT - Assembled 480x320 3.5" TFT+Touchscreen for Raspberry Pi

[PiTFT - Assembled 480x320 3.5" TFT+Touchscreen for Raspberry Pi](https://www.adafruit.com/product/2097)
Is this not the cutest, little display for the Raspberry Pi? It features a **3.5" display with 480x320** 16-bit color pixels and a resistive touch overlay so is slightly larger than [our popular original](https://www.adafruit.com/product/1601). The plate uses the...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2097)
[Related Guides to the Product](https://learn.adafruit.com/products/2097/guides)
![Top down view of a white hand touching the display of a PiTFT - Assembled 480x320 3.5" TFT+Touchscreen for Raspberry Pi.](https://cdn-shop.adafruit.com/640x480/2097-05.jpg)

But our other PiTFT's will also work just fine

### PiTFT Plus 320x240 3.2" TFT + Resistive Touchscreen

[PiTFT Plus 320x240 3.2" TFT + Resistive Touchscreen](https://www.adafruit.com/product/2616)
Is this not the cutest little display for the Raspberry Pi? It features a 3.2" display with 320x240 16-bit color pixels and a resistive&nbsp;touch overlay. The plate uses the high speed SPI interface on the Pi and can use the mini display as a console, X window port, displaying images or...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2616)
[Related Guides to the Product](https://learn.adafruit.com/products/2616/guides)
![Pink polished finger touching the screen of a PiTFT Plus 320x240 3.2" TFT + Resistive Touchscreen. ](https://cdn-shop.adafruit.com/640x480/2616-00.jpg)

### PiTFT Plus Assembled 320x240 2.8" TFT + Resistive Touchscreen

[PiTFT Plus Assembled 320x240 2.8" TFT + Resistive Touchscreen](https://www.adafruit.com/product/2298)
Is this not the cutest little display for the Raspberry Pi? It features a 2.8" display with 320x240 16-bit color pixels and a resistive&nbsp;touch overlay. The plate uses the high speed SPI interface on the Pi and can use the mini display as a console, X window port, displaying images or...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2298)
[Related Guides to the Product](https://learn.adafruit.com/products/2298/guides)
![Red polished white finger touching the PiTFT Plus Assembled 320x240 2.8" TFT + Resistive Touchscreen. ](https://cdn-shop.adafruit.com/640x480/2298-16.jpg)

### Adafruit PiTFT 2.4" HAT Mini Kit - 320x240 TFT Touchscreen

[Adafruit PiTFT 2.4" HAT Mini Kit - 320x240 TFT Touchscreen](https://www.adafruit.com/product/2455)
Is this not the cutest little display for the Raspberry Pi? It features a 2.4" display with 320x240 16-bit color pixels and a resistive touch overlay. The HAT uses the high speed SPI interface on the Pi and can use the mini display as a console, X window port, displaying images or video...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2455)
[Related Guides to the Product](https://learn.adafruit.com/products/2455/guides)
![Black polished white finger touching Adafruit PiTFT 2.4" HAT display in a Adafruit PiTFT 2.4" HAT Mini Kit.](https://cdn-shop.adafruit.com/640x480/2455-08.jpg)

### Adafruit PiTFT 2.2" HAT Mini Kit - 320x240 2.2" TFT - No Touch

[Adafruit PiTFT 2.2" HAT Mini Kit - 320x240 2.2" TFT - No Touch](https://www.adafruit.com/product/2315)
The cute PiTFT got even more adorable with this little primary display for Raspberry Pi in HAT form! It features a 2.2" display with 320x240 16-bit color pixels. The HAT uses the high-speed SPI interface on the Pi and can use the mini display as a console, X window port, displaying images...

In Stock
[Buy Now](https://www.adafruit.com/product/2315)
[Related Guides to the Product](https://learn.adafruit.com/products/2315/guides)
![Top down view of a Adafruit PiTFT 2.2" HAT Mini Kit with desktop image on the display. ](https://cdn-shop.adafruit.com/640x480/2315-04.jpg)

## Cooling It Down

The Raspberry Pi 4 can run a little hot, especially when TensorFlow is doing a lot of data crunching. If you don't have the BrainCraft hat with the built-in fan, we recommend the Pimoroni Fan SHIM.

Or this mini 5V fan

### Miniature 5V Cooling Fan for Raspberry Pi (and Other Computers)

[Miniature 5V Cooling Fan for Raspberry Pi (and Other Computers)](https://www.adafruit.com/product/3368)
Looking for another way to keep your [Raspberry Pi](https://www.adafruit.com/products/3055)&nbsp;_cool_? Hook up this&nbsp; **5V Mini Cooling Fan** &nbsp;and prevent your hard-working Pi from overheating! Of course, it's also great for use with any small...

In Stock
[Buy Now](https://www.adafruit.com/product/3368)
[Related Guides to the Product](https://learn.adafruit.com/products/3368/guides)
![Miniature 5V Cooling Fan for Raspberry Pi and Other Computers](https://cdn-shop.adafruit.com/640x480/3368-00.jpg)

Or if you have the Pi 5, you can use an official cooler.

### Official Raspberry Pi 5 Active Cooler

[Official Raspberry Pi 5 Active Cooler](https://www.adafruit.com/product/5815)
The **Raspberry Pi 5 Active Cooler** is compatible with the [Raspberry Pi 5](https://www.adafruit.com/search?q=raspberry+pi+5) and the [Raspberry Pi 5 Case](http://www.adafruit.com/product/5816). Designed for anyone who wants to push the performance of their...

In Stock
[Buy Now](https://www.adafruit.com/product/5815)
[Related Guides to the Product](https://learn.adafruit.com/products/5815/guides)
![Angled shot of a cooling fan installed on a green microcontroller.](https://cdn-shop.adafruit.com/640x480/5815-04.jpg)

Or tall heatsink

### Aluminum Heat Sink for Raspberry Pi 3 or 4 - 15 x 15 x 15mm

[Aluminum Heat Sink for Raspberry Pi 3 or 4 - 15 x 15 x 15mm](https://www.adafruit.com/product/3082)
Looking for the best heat sink for your [Raspberry Pi](https://www.adafruit.com/products/3055)? Check out this nice and tall **15x15x15mm Heat Sink!**

This heat sink is made from high quality aluminum and will work perfectly with any <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/3082)
[Related Guides to the Product](https://learn.adafruit.com/products/3082/guides)
![Square aluminum heat sink with 20 fins](https://cdn-shop.adafruit.com/640x480/3082-05.jpg)

In order to fit the fan/heatsink along with the display, you will need a GPIO stacking header.

### GPIO Stacking Header for Pi A+/B+/Pi 2/Pi 3/Pi 4/Pi 5

[GPIO Stacking Header for Pi A+/B+/Pi 2/Pi 3/Pi 4/Pi 5](https://www.adafruit.com/product/2223)
Connect your own PCB to a Raspberry Pi B+ and stack on top with this normal-height female header with extra long pins. &nbsp;The female header part is about 8.5mm tall, good for small HATs that do not to clear the USB/Ethernet jacks. This header has extra long 10mm pins, compared with our <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/2223)
[Related Guides to the Product](https://learn.adafruit.com/products/2223/guides)
![Angled top shot of the 2x20 extra tall socket header.](https://cdn-shop.adafruit.com/640x480/2223-08.jpg)

## Longer Camera Cable

The flex cable that comes with the camera is a bit on the short side, so you may want a longer cable as well.

### Raspberry Pi 5 FPC Camera Cable - 22-pin 0.5mm to 15-pin 1mm

[Raspberry Pi 5 FPC Camera Cable - 22-pin 0.5mm to 15-pin 1mm](https://www.adafruit.com/product/5820)
This **500mm&nbsp;long** &nbsp; **camera cable** &nbsp;is specifically designed to work with the&nbsp; **Raspberry Pi 5** &nbsp;series.&nbsp;Just plug it into your Pi 5's camera port and then the other end into one of the official&nbsp;<a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/5820)
[Related Guides to the Product](https://learn.adafruit.com/products/5820/guides)
![angled shot of green, credit-card-sized microcontroller connected via a 500mm long FPC ribbon cable to a camera module.](https://cdn-shop.adafruit.com/640x480/5820-03.jpg)

### Flex Cable for Raspberry Pi Camera or Display - 24" / 610mm

[Flex Cable for Raspberry Pi Camera or Display - 24" / 610mm](https://www.adafruit.com/product/1731)
This cable will let you swap out the stock 150mm long flex cable from a Raspberry Pi Camera (either 'classic' or 'NoIR' type)&nbsp;or Raspberry Pi Display for a different size. Works great, just carefully open the connector on the Pi and slip this one in.  
  
This cable...

In Stock
[Buy Now](https://www.adafruit.com/product/1731)
[Related Guides to the Product](https://learn.adafruit.com/products/1731/guides)
![Angled shot of Flex Cable for Raspberry Pi Camera or Display - 24" / 610mm.](https://cdn-shop.adafruit.com/640x480/1731-04.jpg)

### Flex Cable for Raspberry Pi Camera or Display - 18" / 457mm

[Flex Cable for Raspberry Pi Camera or Display - 18" / 457mm](https://www.adafruit.com/product/1730)
This cable will let you swap out the stock 150mm long flex cable from a Raspberry Pi Camera (either 'classic' or 'NoIR' type) or Raspberry Pi Display for a different size. Works great, just carefully open the connector on the Pi and slip this one in.  
  
This cable is...

Out of Stock
[Buy Now](https://www.adafruit.com/product/1730)
[Related Guides to the Product](https://learn.adafruit.com/products/1730/guides)
![Angled shot of Flex Cable for Raspberry Pi Camera or Display - 18" / 457mm.](https://cdn-shop.adafruit.com/640x480/1730-03.jpg)

# Running TensorFlow Lite Object Recognition on the Raspberry Pi 4 or Pi 5

## Initial Setup

This guide was originally written for Raspberry Pi OS Buster, with the original Picamera library. When Raspberry Pi released Bullseye, they did so with a promise that eventually there would be a new Picamera2 library that was built on top of the libcamera subsystem. While it was possible to install Picamera2, it was a very involved process that was not friendly to the average user and still highly experimental.

Nearly a year later, they started including Picamera2 with Raspberry Pi OS by default, so it was time for a guide update. The installation path that this updated guide uses is designed to make it as easy as possible for you to get a Raspberry Pi up and running with TensorFlow.

The overall installation path will be to using the 64-bit version of the Raspberry Pi Desktop because recent versions of TensorFlow are no longer compiling for the 32-bit OS and the QT OpenGL graphics drivers are installed by default on the Desktop version.

## Image Installation

You're going to get started using the latest Raspbian Pi OS Desktop. Start by downloading and installing the latest Raspberry Pi Imager, which makes it super easy to customize all your settings before you even write the image to the SD Card.

[Latest Raspberry Pi Imager Downloads Page](https://www.raspberrypi.com/software/)
Use the imager to burn the operating system image to a Micro SD Card. Raspberry Pi has provided a quick video overview available to watch.

https://www.youtube.com/watch?v=ntaXWS8Lk34

Select the 64-bit Raspberry Pi OS Bullseye Desktop image by going to **Raspberry Pi OS (Other)** → **Raspberry Pi OS (64-bit)**.

![camera_raspberry_pi_imager_choose_os.png](https://cdn-learn.adafruit.com/assets/assets/000/115/818/medium640/camera_raspberry_pi_imager_choose_os.png?1665510595)

You can customize settings for your Pi by clicking the gear icon in the lower righthand corner after choosing your OS.

![camera_raspberry_pi_imager.png](https://cdn-learn.adafruit.com/assets/assets/000/115/813/medium640/camera_raspberry_pi_imager.png?1665510550)

Make sure to enable SSH, set a good username and password, set your WiFi credentials, and update the locale settings to your specific needs.

![camera_raspberry_pi_imager_settings_screen.png](https://cdn-learn.adafruit.com/assets/assets/000/115/819/medium640/camera_raspberry_pi_imager_settings_screen.png?1665510624)

## Log In

After properly unmounting ("ejecting") your card for you computer, go ahead and place the microSD card in the Pi and supply power to boot it up. It may take a few minutes before it's available.

On your computer, assuming you left the username as **pi** and the hostname as **raspberrypi.local** , SSH into the card using the following:

`ssh pi@raspberrypi.local`

If you changed your username or hostname settings in the imager, use those instead.

## Update the Raspberry Pi

Update the Pi

```terminal
sudo apt update
sudo apt upgrade -y
sudo apt install -y python3-pip
sudo apt install --upgrade -y python3-setuptools
```

## Setup Virtual Environment

If you are installing on the Bookworm version of Raspberry Pi OS, you will need to install your python modules in a virtual environment. You can find more information in the [Python Virtual Environment Usage on Raspberry Pi](https://learn.adafruit.com/python-virtual-environment-usage-on-raspberry-pi) guide. To Install and activate the virtual environment, use the following commands:

```terminal
sudo apt install python3.11-venv
python -m venv env --system-site-packages
```

You will need to activate the virtual environment every time the Pi is rebooted. To activate it:

```terminal
source env/bin/activate
```

If needed, you can use `deactivate`, but leave it active for now.

## Upgrade Script

We put together a script to easily make sure your Pi is correctly configured and install Blinka. Although Blinka isn't required for this to work, it's nice to have and this script also enables several other interfaces that are required for this project to work. It requires just a few commands to run. Most of it is installing the dependencies.

```terminal
cd ~
pip3 install --upgrade adafruit-python-shell
wget https://raw.githubusercontent.com/adafruit/Raspberry-Pi-Installer-Scripts/master/raspi-blinka.py
sudo -E env PATH=$PATH python3 raspi-blinka.py
```

If your system default Python is Python 2 (which usually is no longer the case with the recent versions of Raspberry Pi OS), it will ask to confirm that you want to proceed. Choose&nbsp; **yes**.

![camera_sensors_Python_Sys_Default.png](https://cdn-learn.adafruit.com/assets/assets/000/099/378/medium640/camera_sensors_Python_Sys_Default.png?1613076904)

It may take a few minutes to run. When it finishes, it will ask you if you would like to reboot.&nbsp;Choose&nbsp; **yes**.

![camera_sensors_Reboot_Now.png](https://cdn-learn.adafruit.com/assets/assets/000/099/379/medium640/camera_sensors_Reboot_Now.png?1613076939)

# Running TensorFlow Lite Object Recognition on the Raspberry Pi 4 or Pi 5

## Display Setup

## Driver Installation

The first step to setup the display is to install the necessary drivers. Depending on your exact hardware, you have a couple of options. After the driver setup, there are a couple of additional steps below.

### Option 1. BrainCraft HAT Setup

If you have an Adafruit BrainCraft HAT, you'll first want to head over to the [Adafruit BrainCraft HAT - Easy Machine Learning for Raspberry Pi](https://learn.adafruit.com/adafruit-braincraft-hat-easy-machine-learning-for-raspberry-pi) guide and go through the setup process there. Specifically, you'll want to follow the **Audio Setup** , **Fan Service Setup** , and **Display Module Install** pages. This will guide you through all the pieces needed to prepare the Pi.

![](https://cdn-learn.adafruit.com/assets/assets/000/115/858/medium800/camera_braincraft_desktop.jpeg?1665588634)

### Option 2. PiTFT Setup

If you have just a bare PiTFT, you'll want to install the PiTFT Drivers. There is a new installer script now, so it can be installed with just a few commands. First, start by installing a few dependencies and downloading the repo:

```terminal
cd ~
sudo pip3 install --upgrade adafruit-python-shell click
sudo apt-get install -y git
git clone https://github.com/adafruit/Raspberry-Pi-Installer-Scripts.git
cd Raspberry-Pi-Installer-Scripts
```

Next, choose the install command based on your display. For the **2.4", 2.8", or 3.2" Resistive touchscreens** , use the following command:

```terminal
sudo -E env PATH=$PATH python3 adafruit-pitft.py --display=28r --rotation=90 --install-type=mirror
```

For the **3.5" Resistive touchscreen** , use the following command:

```terminal
sudo -E env PATH=$PATH python3 adafruit-pitft.py --display=35r --rotation=90 --install-type=mirror
```

For the **2.8" Capacitive touchscreen** , use the following command:

```terminal
sudo -E env PATH=$PATH python3 adafruit-pitft.py --display=28c --rotation=90 --install-type=mirror
```

When you get asked to **reboot** , reboot!

![](https://cdn-learn.adafruit.com/assets/assets/000/095/514/medium800/camera_PiTFT_Reboot.png?1602190984)

After it reboots, you should now see your desktop on the display.

![](https://cdn-learn.adafruit.com/assets/assets/000/115/862/medium800/camera_pitft_desktop.jpeg?1665600686)

## Make the TFT the Default Display

With the Desktop Environment, you can set the default display by setting an environment variable. To set the TFT as the display where the window is drawn, there are a few ways to do this depending on the level of permanence that you would like to give it. Each way involves setting the **DISPLAY** environment variable to `:0`.

The first way is to prefix every command with `DISPLAY=:0`. This sets the enviroment variable until the command is done executing. So if you wanted to run **libcamera-hello** , you would type out:

```terminal
DISPLAY=:0 libcamera-hello
```

The second way is to set the variable for the remainder of the SSH terminal session. To do this, just run the command every time you SSH into the Pi:

```terminal
export DISPLAY=:0
```

The third way is to set it in a file that automatically runs each time you connect with SSH such as **.bashrc**. Of course this also assumes you continue using bash as your default shell. To make a backup of your current **.bashrc** file and add it, just run these commands:

```terminal
cp ~/.bashrc ~/.bashrc.backup
echo "export DISPLAY=:0" &gt;&gt; ~/.bashrc
source ~/.bashrc
```

For the sake of simplicity, this guide will assume you are using one of the latter two methods. If you wanted to use the first method, just prefix it to any command that uses the camera such as the libcamera apps or any of the rpi-vision demos.

# Running TensorFlow Lite Object Recognition on the Raspberry Pi 4 or Pi 5

## Camera Test

Now to do an initial test with the camera to make sure the hardware is working before diving into TensorFlow. This should display what the camera sees on the display.

```terminal
libcamera-hello -t 0
```

Press Ctrl+C to exit the test.

Here's what it looks like on the BrainCraft HAT:

![](https://cdn-learn.adafruit.com/assets/assets/000/115/859/medium800/braincraft_cameratest.jpeg?1665591470)

And on the PiTFT, it should look something like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/080/450/medium800/camera_raspistill_test.jpeg?1567620785)

If you don't see anything on your camera or get an error message, be sure you have the camera interface enabled in **raspi-config**. Also, be sure the camera cable is not inserted backwards. If it is still having issues, you will need to get that working before continuing. Unfortunately troubleshooting a camera setup can be complex and is beyond the scope of this guide.

# Running TensorFlow Lite Object Recognition on the Raspberry Pi 4 or Pi 5

## TensorFlow 2 Setup

## Install requirements

There are a few Python packages that TensorFlow requires that need to be installed:

```terminal
sudo apt install -y python3-numpy python3-pillow python3-pygame
```

Install the Speech Output package

```terminal
sudo apt install -y festival
```

## Install rpi-vision

Now to install an Adafruit fork of a program originally written by Leigh Johnson that uses the MobileNet V2 model to detect objects. While there is a MobileNet V3, it isn't as accurate as V2. This part will take a few minutes to complete.

```terminal
cd ~
source env/bin/activate
git clone --depth 1 https://github.com/adafruit/rpi-vision.git
cd rpi-vision
pip3 install -e .
```

![](https://cdn-learn.adafruit.com/assets/assets/000/115/860/medium800/camera_rpi-vision_install.png?1665592434)

## Install TensorFlow 2.x

Next you can download and install Tensorflow 2. There are a nice set of releases over on [PINTO0309's GitHub Releases Page.](https://github.com/PINTO0309/Tensorflow-bin/releases) To install TensorFlow 2.15.0, run the following commands. This cryptic bit of shell code figures out the current version of CPython running on your Pi, substitutes that in, and then downloads and installs the appropriate release file.

```terminal
RELEASE=https://github.com/PINTO0309/Tensorflow-bin/releases/download/v2.15.0.post1/tensorflow-2.15.0.post1-cp311-none-linux_aarch64.whl
CPVER=$(python --version | grep -Eo '3\.[0-9]{1,2}' | tr -d '.')
pip install $(echo "$RELEASE" | sed -e "s/cp[0-9]\{3\}/CP$CPVER/g")
```

![](https://cdn-learn.adafruit.com/assets/assets/000/115/861/medium800/camera_tf_install.png?1665595320)

After this, go ahead and reboot the Pi.

```terminal
sudo reboot
```

Warning: 

## Running the Graphic Labeling Demo

Finally you are ready to run the detection software. To run a program that will display the object it sees on screen, type in the following:

```terminal
cd rpi-vision
python3 tests/pitft_labeled_output.py --tflite
```

You should see a bunch of text scrolling in your SSH window.

![](https://cdn-learn.adafruit.com/assets/assets/000/080/453/medium800/camera_detection_text.png?1567623076)

Now start holding up various items in front of the camera and it should display what it thinks it sees, which isn't actually what the item may be. Some items that it's pretty good about identifying are coffee mugs and animals.

![](https://cdn-learn.adafruit.com/assets/assets/000/080/375/medium800/camera_coffee_mug.jpg?1567552636)

![](https://cdn-learn.adafruit.com/assets/assets/000/095/489/medium800thumb/camera_main-image.jpg?1602168691)

## Speech Output

As an added bonus, you can hook up a pair of headphones or a speaker to the Raspberry Pi and it will actually tell you what it is detecting. Make sure you don't have any HDMI cords plugged in though or the audio will go through the monitor.

If you don't hear anything, make sure the sound source you are expecting is selected. With the Raspberry Pi Desktop, you have a couple of ways to do this. If you have a mouse connected, you can right-click the speaker icon in the upper right-hand corner and choose your source.

If you prefer the command line, you can also run **raspi-config** , and go to **System Options** → **Audio** to select it.

If you still don't hear anything, make sure your volume is turned up by using **alsamixer**. For the BrainCraft HAT, this is described in more detail on the [Audio Setup](https://learn.adafruit.com/adafruit-braincraft-hat-easy-machine-learning-for-raspberry-pi/audio-setup) page.

Finally, you can test the text to speech from the command line by running the following command:

```terminal
echo "This is a test" | festival --tts
```


## Featured Products

### Raspberry Pi 4 Model B - 4 GB RAM

[Raspberry Pi 4 Model B - 4 GB RAM](https://www.adafruit.com/product/4296)
The Raspberry Pi 4 Model B is the newest Raspberry Pi computer made, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 4 better than the 3? How about a&nbsp;_faster_ processor, USB 3.0 ports, and updated Gigabit Ethernet chip with...

In Stock
[Buy Now](https://www.adafruit.com/product/4296)
[Related Guides to the Product](https://learn.adafruit.com/products/4296/guides)
### Raspberry Pi Camera Board v2 - 8 Megapixels

[Raspberry Pi Camera Board v2 - 8 Megapixels](https://www.adafruit.com/product/3099)
Snap, snap! The Camera v2 is the new official camera board released by the Raspberry Pi Foundation!

The **Raspberry Pi Camera Board v2** is a high quality 8 megapixel Sony IMX219 image sensor custom designed add-on board for Raspberry Pi, featuring a fixed focus lens....

In Stock
[Buy Now](https://www.adafruit.com/product/3099)
[Related Guides to the Product](https://learn.adafruit.com/products/3099/guides)
### Adafruit BrainCraft HAT - Machine Learning for Raspberry Pi 4

[Adafruit BrainCraft HAT - Machine Learning for Raspberry Pi 4](https://www.adafruit.com/product/4374)
The idea behind the BrainCraft HAT is that you’d be able to “craft brains” for Machine Learning on the EDGE, with Microcontrollers & Microcomputers. On&nbsp;ASK AN ENGINEER, our founder & engineer chatted with&nbsp;Pete Warden, the technical lead of the mobile,...

In Stock
[Buy Now](https://www.adafruit.com/product/4374)
[Related Guides to the Product](https://learn.adafruit.com/products/4374/guides)
### PiTFT - Assembled 480x320 3.5" TFT+Touchscreen for Raspberry Pi

[PiTFT - Assembled 480x320 3.5" TFT+Touchscreen for Raspberry Pi](https://www.adafruit.com/product/2097)
Is this not the cutest, little display for the Raspberry Pi? It features a **3.5" display with 480x320** 16-bit color pixels and a resistive touch overlay so is slightly larger than [our popular original](https://www.adafruit.com/product/1601). The plate uses the...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2097)
[Related Guides to the Product](https://learn.adafruit.com/products/2097/guides)
### PiTFT Plus 320x240 3.2" TFT + Resistive Touchscreen

[PiTFT Plus 320x240 3.2" TFT + Resistive Touchscreen](https://www.adafruit.com/product/2616)
Is this not the cutest little display for the Raspberry Pi? It features a 3.2" display with 320x240 16-bit color pixels and a resistive&nbsp;touch overlay. The plate uses the high speed SPI interface on the Pi and can use the mini display as a console, X window port, displaying images or...

Out of Stock
[Buy Now](https://www.adafruit.com/product/2616)
[Related Guides to the Product](https://learn.adafruit.com/products/2616/guides)
### Pimoroni Fan SHIM for Raspberry Pi

[Pimoroni Fan SHIM for Raspberry Pi](https://www.adafruit.com/product/4316)
Looking for another way to keep your [Raspberry Pi](https://www.adafruit.com/category/105)&nbsp;_cool?_ Hook up Pimoroni's miniature 5V&nbsp; **Fan** &nbsp; **SHIM** and prevent your hard-working Pi from overheating! It'll keep your Pi running...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/4316)
[Related Guides to the Product](https://learn.adafruit.com/products/4316/guides)
### Miniature 5V Cooling Fan for Raspberry Pi (and Other Computers)

[Miniature 5V Cooling Fan for Raspberry Pi (and Other Computers)](https://www.adafruit.com/product/3368)
Looking for another way to keep your [Raspberry Pi](https://www.adafruit.com/products/3055)&nbsp;_cool_? Hook up this&nbsp; **5V Mini Cooling Fan** &nbsp;and prevent your hard-working Pi from overheating! Of course, it's also great for use with any small...

In Stock
[Buy Now](https://www.adafruit.com/product/3368)
[Related Guides to the Product](https://learn.adafruit.com/products/3368/guides)
### Aluminum Heat Sink for Raspberry Pi 3 or 4 - 15 x 15 x 15mm

[Aluminum Heat Sink for Raspberry Pi 3 or 4 - 15 x 15 x 15mm](https://www.adafruit.com/product/3082)
Looking for the best heat sink for your [Raspberry Pi](https://www.adafruit.com/products/3055)? Check out this nice and tall **15x15x15mm Heat Sink!**

This heat sink is made from high quality aluminum and will work perfectly with any <a...></a...>

In Stock
[Buy Now](https://www.adafruit.com/product/3082)
[Related Guides to the Product](https://learn.adafruit.com/products/3082/guides)

## Related Guides

- [Raspberry Pi Care and Troubleshooting](https://learn.adafruit.com/raspberry-pi-care-and-troubleshooting.md)
- [Adafruit BrainCraft HAT - Easy Machine Learning for Raspberry Pi](https://learn.adafruit.com/adafruit-braincraft-hat-easy-machine-learning-for-raspberry-pi.md)
- [apt.adafruit.com](https://learn.adafruit.com/apt-adafruit-com.md)
- [BrainCraft Camera Case](https://learn.adafruit.com/braincraft-camera-case.md)
- [Using OSC to Communicate with a Raspberry Pi](https://learn.adafruit.com/raspberry-pi-open-sound-control.md)
- [Adafruit PiTFT 3.5" Touch Screen for Raspberry Pi](https://learn.adafruit.com/adafruit-pitft-3-dot-5-touch-screen-for-raspberry-pi.md)
- [Processing on the Raspberry Pi & PiTFT](https://learn.adafruit.com/processing-on-the-raspberry-pi-and-pitft.md)
- [PiTFT Python + Pillow Animated Gif Player](https://learn.adafruit.com/pitft-linux-python-animated-gif-player.md)
- [diy lofi hip hop raspberry pi radio](https://learn.adafruit.com/lofi-hip-hop-raspberry-pi-radio-braincraft.md)
- [Raspberry Pi + Teachable Machine = Teachable Pi](https://learn.adafruit.com/teachable-machine-raspberry-pi-tensorflow-camera.md)
- [Build an ML Package Detector with Lobe](https://learn.adafruit.com/build-an-ml-package-detector.md)
- [AstroPrint 3D Printing](https://learn.adafruit.com/astroprint-3d-printing.md)
- [Build an ML Rock Paper Scissors Game with Lobe](https://learn.adafruit.com/lobe-rock-paper-scissors.md)
- [Freq Show: Raspberry Pi RTL-SDR Scanner](https://learn.adafruit.com/freq-show-raspberry-pi-rtl-sdr-scanner.md)
- [Python Edge Speech Recognition with Voice2JSON](https://learn.adafruit.com/edge-speech-recognition-with-voice2json.md)
- [CYBERDECK Expansion Plate](https://learn.adafruit.com/cyberdeck-plate.md)
- [Adafruit IO Connected Animated GIF Display](https://learn.adafruit.com/adafruit-io-connected-animated-gif-display.md)
