There are multiple ways of getting the inference results from a TAPPAS pipeline in Python, both before or after post-processing.
GstHailoPython Element
The HailoPython
module offers a seamless entry point for user-defined Python scripts within the TAPPAS pipeline. It grants access to both raw and post-processed outputs, alongside the GStreamer buffer.
–To obtain raw outputs using the HailoPython
element: replace the hailofilter
element with hailopython module=$PATH_TO_MODULE/my_module.py
.
– For accessing post-processed outputs: add hailopython module=$PATH_TO_MODULE/my_module.py
after the hailofilter
.
Here’s an example of what the Python module would look like:
import hailo
# Importing VideoFrame before importing GST is must
from gsthailo import VideoFrame
from gi.repository import Gst
def run(video_frame: VideoFrame):
for tensor in video_frame.roi.get_tensors():
print(tensor.name())
my_tensor = roi.get_tensor("output_layer_name")
print(f"shape is {my_tensor.height()}X{my_tensor.width()}X{my_tensor.features()})
HailoImportZMQ
HailoImportZMQ is an element which provides an access point in the pipeline to import HailoObjects meta from a ZMQ socket. The meta is added to any pre-existing ROI in the buffer, and then the buffer continues onwards in the pipeline.
Here’s an example of implementing this feature using Python for the client-side:
Server-Side Pipeline
gst-launch-1.0 filesrc location=detection.mp4 name=src_0 ! \
decodebin ! videoscale ! video/x-raw, pixel-aspect-ratio=1/1 ! \
videoconvert ! queue leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 ! \
hailonet hef-path=./resources/yolov5m_wo_spp_60p.hef is-active=true batch-size=1 ! \
queue leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 ! \
hailofilter function-name=yolov5 so-path=/local/workspace/tappas/apps/gstreamer/libs/post_processes/libyolo_post.so config-path=/local/workspace/tappas/apps/gstreamer/general/detection/resources/configs/yolov5.json qos=false ! \
queue leaky=no max-size-buffers=30 max-size-bytes=0 max-size-time=0 ! \
hailooverlay ! \
hailoexportzmq ! \
videoconvert ! \
fpsdisplaysink video-sink=xvimagesink name=hailo_display sync=false text-overlay=false
Client-side (Python)
import zmq
port = "5555"
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.setsockopt_string(zmq.SUBSCRIBE, "")
print("Collecting updates from weather server...")
socket.connect(f'tcp://localhost:{port}')
while True:
print(socket.recv())