You can broadcast predictions from
YOLOv8 Over UDP
. 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 UDP
.
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!
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.
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 cv2
from inference.core.interfaces.stream.inference_pipeline import InferencePipeline
from inference.core.interfaces.stream.sinks import UDPSink
udp_sink = UDPSink.init(ip_address="127.0.0.1", port=9090)
pipeline = InferencePipeline.init(
model_id="your-model/3",
video_reference=0,
on_prediction=udp_sink.send_predictions,
)
pipeline.start()
pipeline.join()
Above, replace `127.0.0.1` and `9090` with the host address on which your UDP server is running and the port on which the model is running.
You will then need to start a UDP server that can receive predictions. Here is an example of a UDP server:
import json
import os
import socket
HOST = os.getenv("HOST", "127.0.0.1")
PORT = int(os.getenv("PORT", "9090"))
BUFFER_SIZE = 65535
def main() -> None:
udp_socket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
udp_socket.bind((HOST, PORT))
try:
while True:
message, _ = udp_socket.recvfrom(BUFFER_SIZE)
decoded_message = message.decode("utf-8")
parsed_message = json.loads(decoded_message)
print(parsed_message)
finally:
udp_socket.close()
if __name__ == '__main__':
main()
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.
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.