Installing Frigate on Raspberry Pi 5 with a Google Coral TPU

Frigate is a versatile Network Video Recorder that is quick and easy to get up and running thanks to its ready to go Docker images and simple user interface. 

You can use it to monitor, record, and perform object detection (with suitable hardware, we’ll get to that a little later) on your various camera feeds so you can keep an eye on your home, office, or anywhere you may need to watch! 

What You’ll Need

The hardware needed here is going to be identical to that in our Raspberry Pi 5 PyCoral piece as we’re utilising the same Google Coral TPU to do some object detection later on and not have to rely on the Pi 5’s own CPU. 

So from that, you’ll need a Raspberry Pi 5 with the latest Raspberry Pi OS installed to a microSD card, as well as a PCIe HAT to connect your Google Coral TPU to. 

For this particular use case we’d definitely recommend grabbing a HatDrive! AI where you can run your TPU alongside fast NVMe boot storage as you’ll want something more than a microSD card for constant recording of video feeds if that’s your plan. For testing and playing around though, a good microSD card should suit you fine. 

Setting Up Your Raspberry Pi 5 to Work With The TPU

Ensure Raspberry Pi OS is Up To Date

As Raspberry Pi OS was just installed for this, you likely won’t have any package updates but it’s good practice to double check just in case. 

Run the following commands to ensure everything is up to date 

sudo apt update 
sudo apt upgrade 

Modifying the config.txt File

We need to make a few changes to the config.txt file to make sure the Coral TPU is able to run, so open /boot/firmware/config.txt with your chosen text editor (with sudo) and add the following lines to the end of your file. 

 

kernel=kernel8.img 
dtoverlay=pineboards-hat-ai 

 

These enable the PCIe connection on the Raspberry Pi 5 (just in case, it’s enabled by default these days), switch the kernel to use 4K block sizes (a requirement of the Coral TPU), and enable the Pineboards AI Hat device tree overlay to tweak things that are needed for the TPU to run as expected. 

Now, it’s time to reboot and apply the changes. A quick sudo reboot command is enough for this. 

Once back up, check with uname –a make sure the Linux kernel version has updated. You should see 6.6.31+rpt-rpi-v8, and it’s the v8 we’re looking for at the end. If it’s there, the change was successful. 

To check the Google Coral is showing up as a device on the machine, run lspci | grep Coral which should then report System peripheral: Global Unichip Corp. Coral Edge TPU. If it doesn’t, make sure that everything is physically connected as per the instructions of your PCIe HAT and that all previous instructions in this guide have been followed correctly. 

 

Installing the Necessary Drivers for the Coral TPU

To kick things off, you’ll need to follow our how to configure the Google Coral TPU on the Raspberry Pi 5 from Step 3 (we’ve performed Steps 1 and 2 already) as it will walk you through each step of installing the necessary drivers and software for the TPU to run. 

Installing Docker for Raspberry Pi 5

Following Docker’s own instructions for installing Docker via their apt repository, run the following: 

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/debian/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/debian \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update 

This will add Docker’s GPG key, install some necessary packages, and add the Docker APT repository to your sources.list file so that you can then download their packages: 


sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-compose 

 

Once you confirm the installation of the above packages, you should be ready to go with Docker! 

Creating the Frigate Docker Container

Docker is the recommended method of installing Frigate by the creators themselves, so who are we to argue? 

Important Note: For this guide, we will be utilising a PCIe Google Coral TPU, local storage for recordings, and a single network camera over the RTSP protocol. Our configuration file will be set up for this setup. If you wish to use a different setup, the Frigate documentation will help you with that. 

Create the necessary files and directories 

In the next section, we’re going to need directories for your config and storage, and whilst it could create them for you, it’s best to decide where you want to store this data and create them ahead of time. 

I’m going to use /home/user/frigate/config/ and /home/user/frigate/storage/ for these, so I’ll run: 
 

mkdir –p /home/user/frigate/config 
mkdir –p /home/user/frigate/storage 

We’ll also need a config file, and this will be in the above config directory: 
 
nano /home/user/frigate/config/config.yml 

 

In this file, we’ll start with the following, as I have my camera in the living room and its IP is 192.168.1.123 

mqtt:
  enabled: False
  
detectors:
  coral:
    type: edgetpu
    device: pci 

cameras:
  living_room:
    enabled: False
    ffmpeg:
      inputs:
        - path: rtsp://192.168.1.123/stream1
          roles:
            - detect

Docker Compose

A docker-compose.yml file is how we’re going to configure the Docker deployment itself, and we’ll take the default from their installation page and modify it a little. Make sure to change the password on the final line! Use your chosen text editor (I’ll use nano in the example) and create this in the /home/user/frigate directory. 

 

cd /home/user/frigate 
nano docker-compose.yml 


Then enter the following: 
 

version: "3.9"
services:
  frigate:
    container_name: frigate
    privileged: true # this may not be necessary for all setups
    restart: unless-stopped
    image: ghcr.io/blakeblackshear/frigate:stable
    shm_size: "64mb" # update for your cameras based on calculation above
    devices:
      - /dev/apex_0:/dev/apex_0    # Passes a PCIe Coral, follow driver instructions here https://coral.ai/docs/m2/get-started/#2a-on-linux
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /home/user/frigate/config:/config
      - /home/user/frigate/storage:/media/frigate
      - type: tmpfs # Optional: 1GB of memory, reduces SSD/SD Card wear
        target: /tmp/cache
        tmpfs:
          size: 1000000000
    ports:
      - "5000:5000"
      - "8554:8554" # RTSP feeds
      - "8555:8555/tcp" # WebRTC over tcp
      - "8555:8555/udp" # WebRTC over udp
    environment:
      FRIGATE_RTSP_PASSWORD: "pineberriesandcream"

 

To then deploy the Docker container, we’ll use docker-compose: 

 sudo docker-compose up -d
 

If all went well, you’ll be able to access your new Frigate instance at http://192.168.1.123:5000, obviously changing the IP to that of your own Raspberry Pi, and you’ll see the following screen 

    

From this you can see that our Google Coral TPU is recognised, and the Living Room camera has been set up correctly. 

 

Testing Object Detection

Before we wrap this up, we can check out object detection in the Frigate UI. The Coral TPU detector will run with the edgetpu_model.tflite (Tensorflow Lite) by default here. 

If you go to the camera you want to do the detection on, you’ll see a “Live” and “Debug” option in the top right-hand corner. Click on Debug and you’ll have a set of options to choose from. 

 

    

If you enable the “Bounding box” option and then walk in the frame, you’ll be able to see it detect you and label you (hopefully) as a person. Unless you’re a dog, then maybe it will say dog. Though if you’re a dog, I'm thoroughly impressed you made it this far. 

Conclusion

With everything we’ve gone through in this guide, you will now have a basic, 1-camera Frigate NVR setup with the Google Coral TPU running inference, leaving your CPU to handle other tasks. 

From here, there are no end of options available to you. Be it setting your cameras up to record constantly or when there’s activity/movement or, as I’ve done, integrating it into Home Assistant so that you can manage and trigger other aspects of your smart home. 

If you want to see the full range of things that Frigate can do, head to their full documentation page and browse to your heart’s content. 

 

 

Back to blog