Getting started with the RPi5 AI kit... How am I supposed to use any of this?

I am using object detection for a hobby project.

My first approach ran on my PC. It used my PC’s GPU, PyTorch, and Ultralytics to analyze a frame from a webcam and draw some boxes and labels on the things it saw onscreen. The AI-related code to do that clocked in at 8 lines:

import torch
from ultralytics import YOLO

class AI_YOLOv8:
    def __init__(self):
        self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
        self.model = YOLO("yolov8n-seg.pt").to(self.device)

    def get_objects(self, image):
        return self.model(image)

However, I recently switched from my desktop PC to a Raspberry Pi 5 + AI Kit for this project. The old code still works on the Pi 5, but since the Pi 5 lacks a beefy GPU, it runs at 1 FPS.

Enter the Hailo8L.

I naively expected the code to be more or less the same, but maybe replacing self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')with self.device = torch.device('hailo8l' if hailo8l.is_available() else 'cpu').

Nooooooooooooope.

From what I can tell, the object detection python script is ~250 lines long, with another ~250 lines in the core python file. There is no easy way to integrate this into my existing program without quadrupling the amount of code and complexity.

I’ve gone through every line of code in both the detection.py file and the hailo_rpi_common.py file, and with each new line I come away with more questions than answers. Like wtf is a GStreamer? Why does this use a pipeline, and what is a pipeline? What’s a source_element? Why is there no function like hailo.detect_objects_in_image()?

How am I supposed to use any of this?

I have two questions:

  1. Does anyone know of a simple, easy-to-understand example that isn’t half a thousand lines long?
  2. Why is the golden path example for this half a thousand lines long, while the Torch example is only 8 lines long?

Hey @austin2baccus,

Welcome to the Hailo Community!

To get started smoothly, here are the key steps:

  1. Convert Your PyTorch File to HEF: Before running your model on Hailo, you’ll need to convert your PyTorch file into an HEF file. For detailed instructions, download the DFC and refer to our guide here: Hailo Developer Zone.
  2. Use the HEF File with Hailo: Once you have the HEF file, you can integrate it with Hailo. Here’s an example of how to use the Hailo Python API: Hailo Application Code Examples.

Tip: If you’d like to test your code with our YOLOv8n model, check out our ready-to-use model here: Hailo Model Zoo.


Let me know if there’s anything else you need!