diff --git a/tests/hailo.py b/tests/hailo.py new file mode 100644 index 00000000..0b5976bd --- /dev/null +++ b/tests/hailo.py @@ -0,0 +1,95 @@ +#!/bin/python3 + +import os + +try: + from picamera2.devices import Hailo, hailo_architecture +except ImportError: + print("SKIPPED (hailo_platform not installed)") + quit() + +from picamera2 import Picamera2 + +# Check a Hailo device is present. +arch = hailo_architecture() +if arch is None: + print("SKIPPED (no Hailo device found)") + quit() + +# Pick models based on architecture. +if arch == 'HAILO10H': + detect_model = '/usr/share/hailo-models/yolov8m_h10.hef' + pose_model = '/usr/share/hailo-models/yolov8s_pose_h10.hef' +else: + detect_model = '/usr/share/hailo-models/yolov8s_h8l.hef' + pose_model = '/usr/share/hailo-models/yolov8s_pose_h8l_pi.hef' + +if not os.path.exists(detect_model): + print("SKIPPED (detection model not found:", detect_model + ")") + quit() +if not os.path.exists(pose_model): + print("SKIPPED (pose model not found:", pose_model + ")") + quit() + +NUM_FRAMES = 30 + +# Test detection model over 30 frames. +print("Testing detection model:", detect_model) +with Hailo(detect_model) as hailo: + input_shape = hailo.get_input_shape() + print("Input shape:", input_shape) + if len(input_shape) != 3: + print("ERROR: expected 3-dimensional input shape, got", len(input_shape)) + + inputs, outputs = hailo.describe() + print("Model inputs:", len(inputs), "outputs:", len(outputs)) + if len(inputs) < 1: + print("ERROR: expected at least 1 input layer") + if len(outputs) < 1: + print("ERROR: expected at least 1 output layer") + + with Picamera2() as picam2: + model_h, model_w = input_shape[0], input_shape[1] + config = picam2.create_preview_configuration( + main={'size': (1920, 1080), 'format': 'XRGB8888'}, + lores={'size': (model_w, model_h), 'format': 'RGB888'} + ) + picam2.configure(config) + picam2.start() + + for i in range(NUM_FRAMES): + frame = picam2.capture_array('lores') + result = hailo.run(frame) + if result is None: + print("ERROR: detection inference returned None on frame", i) + break + else: + print("Detection model: all", NUM_FRAMES, "frames returned results") + + picam2.stop() + +# Test pose estimation model over 30 frames. +print("Testing pose model:", pose_model) +with Hailo(pose_model) as hailo: + input_shape = hailo.get_input_shape() + print("Input shape:", input_shape) + + with Picamera2() as picam2: + model_h, model_w = input_shape[0], input_shape[1] + config = picam2.create_preview_configuration( + main={'size': (1920, 1080), 'format': 'XRGB8888'}, + lores={'size': (model_w, model_h), 'format': 'RGB888'} + ) + picam2.configure(config) + picam2.start() + + for i in range(NUM_FRAMES): + frame = picam2.capture_array('lores') + result = hailo.run(frame) + if result is None: + print("ERROR: pose inference returned None on frame", i) + break + else: + print("Pose model: all", NUM_FRAMES, "frames returned results") + + picam2.stop() diff --git a/tests/imx500.py b/tests/imx500.py new file mode 100644 index 00000000..5bf92804 --- /dev/null +++ b/tests/imx500.py @@ -0,0 +1,49 @@ +#!/bin/python3 + +import os + +from picamera2 import Picamera2 +from picamera2.devices.imx500 import IMX500 + +# Check if an imx500 camera is connected. +camera_info = Picamera2.global_camera_info() +camera_num = next((c['Num'] for c in camera_info if c['Model'] == 'imx500'), None) + +if camera_num is None: + print("SKIPPED (no imx500 camera found)") + quit() + +model_path = '/usr/share/imx500-models/imx500_network_ssd_mobilenetv2_fpnlite_320x320_pp.rpk' +if not os.path.exists(model_path): + print("SKIPPED (model file not found:", model_path + ")") + quit() + +imx500 = IMX500(model_path) + +# Test getting the device ID. +device_id = imx500.get_device_id() +print("Device ID:", device_id) +if not device_id: + print("ERROR: empty device ID") + +# Start the camera and capture some frames with output tensors. +picam2 = Picamera2(imx500.camera_num) +config = picam2.create_preview_configuration(buffer_count=12) +picam2.configure(config) +picam2.start() + +NUM_FRAMES = 30 + +tensor_count = 0 +for _ in range(NUM_FRAMES): + metadata = picam2.capture_metadata() + outputs = imx500.get_outputs(metadata, add_batch=True) + if outputs is not None and len(outputs) > 0: + tensor_count += 1 + +print("Got output tensors on", tensor_count, "of", NUM_FRAMES, "frames") +if tensor_count < NUM_FRAMES // 2: + print("ERROR: expected at least", NUM_FRAMES // 2, "frames with output tensors") + +picam2.stop() +picam2.close() diff --git a/tests/test_list.txt b/tests/test_list.txt index ede08393..c91ed6d1 100644 --- a/tests/test_list.txt +++ b/tests/test_list.txt @@ -85,6 +85,8 @@ tests/encoder_import.py tests/encoder_start_stop.py tests/ffmpeg_abort.py tests/grey_world.py +tests/hailo.py +tests/imx500.py tests/imx708_device.py tests/large_datagram.py tests/mjpeg_server.py