How to broadcast predictions from YOLOv8 Over Apache Kafka

You can broadcast predictions from

YOLOv8 Over Apache Kafka

. This is useful for sending the results of a model to a central system for further processing or logging.

In this guide, we will demonstrate how to broadcast predictions from

YOLOv8 Over Apache Kafka


‍In this guide, we will demonstrate how to broadcast predictions fromWe will:

1. Install supervision
2. Load data
3. Plot predictions with a supervision Annotator

Without further ado, let's get started!

Step #1: Install supervision

First, install the supervision pip package:

pip install supervision

Once you have installed supervision, you are ready to load your data and start writing logic to filter detections.

Step #2: Load Model and Send Data

For this guide, you will need to have a broker set up that can accept predictions. Once you have a broker, you can stream predictions from your model that is running on a video, camera feed, or RTSP stream feed.

You can load the model and send data using the following code:

import json

from kafka import KafkaProducer
from inference import InferencePipeline
from import render_boxes

# add your Kafka broker host name and port
producer = KafkaProducer(bootstrap_servers=['localhost:9092'])

# replace with your Kafka topic name
TOPIC_NAME = "bottle-cap-integrity"

future = producer.send(TOPIC_NAME, b'raw_bytes')

def on_prediction(predictions, video_frame):
    render_boxes(predictions=predictions, video_frame=video_frame)
    predictions = json.dumps(predictions)
    predictions_as_bytes = predictions.encode('utf-8')
    producer.send('bottle-cap-integrity', predictions_as_bytes)

pipeline = InferencePipeline.init(
    model_id="bottle-cap-integrity/7", # replace with your Roboflow YOLOv8 model ID


Once you make the necessary substitutions above and run the script, you should see data being received by your broker for any further processing you implement.

Next steps

supervision provides an extensive range of functionalities for working with computer vision models. With supervision, you can:

1. Process and filter detections and segmentation masks from a range of popular models (YOLOv5, Ultralytics YOLOv8, MMDetection, and more).
2. Process and filter classifications.
3. Compute confusion matrices.

And more! To learn about the full range of functionality in supervision, check out the supervision documentation.