User Guide 3: Simplifying Object Detection on a Hailo Device Using DeGirum PySDK

@kim_jiseob
Glad to hear that you were able to use our AI hub inference. If possible, we would still like to help you solve the issue with running locally.

Thx @shashi Isn’t it possible to calculate the mAP of a custom model only locally? The fact that the value came out of the cloud meant that I just randomly entered the value and checked that it worked.

@kim_jiseob
It is possible to evaluate locally as well. There is definitely some setup issue on your side that we need to debug.

Yes @shashi The problem of not recognizing the model path is the same as commented in Guide 2. Here is my log:
[‘yolov8n’]
dict_keys([‘DUMMY/DUMMY’, ‘HAILORT/HAILO8L’, ‘N2X/CPU’, ‘TFLITE/CPU’])

There are hef and json files in the directory.

@kim_jiseob
In your case, the model list is not empty as it looks like yolov8n is actually listed as an available model.

When I set the versions of hailort, hailofw, and hailo-dkms to 4.19.0, inference was successful with my custom model. thank you so much @shashi

Hi @kim_jiseob
Amazing. Thanks for letting me know. Please feel free to reach out if you need any further help.

1 Like

Good afternoon, I encountered the following issues.

All my files are located in the following directory:

  • HailoDetectionYolo.py
  • labels_coco.json
  • yolov11n.hef
  • yolov11n.json

in this directory:
yolo_check_5/zoo_url/yolov11n

However, when I use the following script:

import degirum as dg
from pprint import pprint

Load the model from the model zoo.

Replace ‘<path_to_model_zoo>’ with the directory containing your model assets.

model = dg.load_model(
model_name=‘yolov11n’,
inference_host_address=‘@local’,
zoo_url=‘yolo_check_5/zoo_url/yolov11n’
)

I get the following error and can’t figure out what the problem is:

Traceback (most recent call last):
File “er.py”, line 6, in
model = dg.load_model(
^^^^^^^^^^^^^^
File “degirum_env/lib/python3.11/site-packages/degirum/init.py”, line 220, in load_model
return zoo.load_model(model_name, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “degirum_env/lib/python3.11/site-packages/degirum/log.py”, line 59, in wrap
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File “degirum_env/lib/python3.11/site-packages/degirum/zoo_manager.py”, line 266, in load_model
model = self._zoo.load_model(model_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “degirum_env/lib/python3.11/site-packages/degirum/log.py”, line 59, in wrap
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File “degirum_env/lib/python3.11/site-packages/degirum/_zoo_accessor.py”, line 309, in load_model
model_params = self.model_info(model)
^^^^^^^^^^^^^^^^^^^^^^
File “degirum_env/lib/python3.11/site-packages/degirum/log.py”, line 59, in wrap
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File “degirum_env/lib/python3.11/site-packages/degirum/_zoo_accessor.py”, line 127, in model_info
raise DegirumException(
degirum.exceptions.DegirumException: Model ‘yolov11n’ is not found in model zoo ‘yolo_check_5/zoo_url/yolov11n’

I have tried many solutions, but I haven’t been able to resolve this issue.

Hi @An_ti11
Can you please check the supported devices in model json match the device you have?

i have hailo8l “{
“ConfigVersion”: 10,
“DEVICE”: [
{
“DeviceType”: “HAILO8L”,
“RuntimeAgent”: “HAILORT”,
“SupportedDeviceTypes”: “HAILORT/HAILO8L”
}
],
“PRE_PROCESS”: [
{
“InputType”: “Image”,
“InputN”: 1,
“InputH”: 640,
“InputW”: 640,
“InputC”: 3,
“InputPadMethod”: “letterbox”,
“InputResizeMethod”: “bilinear”,
“InputQuantEn”: true
}
],
“MODEL_PARAMETERS”: [
{
“ModelPath”: “yolov11n.hef”
}
],
“POST_PROCESS”: [
{
“OutputPostprocessType”: “Detection”,
“PythonFile”: “HailoDetectionYolo.py”,
“OutputNumClasses”: 1,
“LabelsPath”: “labels_coco.json”,
“OutputConfThreshold”: 0.2
}
]
}” it is yolov11n.json

@An_ti11
Please add the below line to your json below the ConfigVersion line:
"Checksum": "d6c4d0b9620dc2e5e215dfab366510a740fe86bf2c5d9bd2059a6ba3fe62ee63",

thanks a lot for help, but now i have such error, i don’t undrestand why "import degirum as dg
from pprint import pprint
import cv2
import numpy as np

Initialize the model from the model zoo

model = dg.load_model(
model_name=‘yolov11n’,
inference_host_address=‘@local’,
zoo_url=‘/home/anton/yolo_check_5/zoo_url/yolov11n’
)

def resize_with_letterbox_image(image, target_height, target_width, padding_value=(0, 0, 0)):
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
h, w, c = image_rgb.shape
scale = min(target_width / w, target_height / h)
new_w = int(w * scale)
new_h = int(h * scale)
resized_image = cv2.resize(image_rgb, (new_w, new_h), interpolation=cv2.INTER_LINEAR)
letterboxed_image = np.full((target_height, target_width, c), padding_value, dtype=np.uint8)
pad_top = (target_height - new_h) // 2
pad_left = (target_width - new_w) // 2
letterboxed_image[pad_top:pad_top+new_h, pad_left:pad_left+new_w] = resized_image
return letterboxed_image, scale, pad_top, pad_left

video_path = “path/to/your/video.mp4”
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
print(“Error: Could not open video.”)
exit()

target_height, target_width = 640, 640 # Remove batch dimension

while True:
ret, frame = cap.read()
if not ret:
break

processed_frame, scale, pad_top, pad_left = resize_with_letterbox_image(frame, target_height, target_width)

# Perform inference with correctly shaped image (H, W, 3)
inference_result = model(processed_frame)

# Debug output
print(type(inference_result), inference_result)

# If the result is a list, extract the first element
if isinstance(inference_result, list):
    inference_result = inference_result[0]

pprint(inference_result.results)

display_frame = cv2.cvtColor(processed_frame, cv2.COLOR_RGB2BGR)
print(f"Scale: {scale:.3f}, Pad top: {pad_top}, Pad left: {pad_left}")

cv2.imshow("Letterboxed Frame", display_frame)
if cv2.waitKey(30) & 0xFF == ord('q'):
    break

cap.release()
cv2.destroyAllWindows()
"

degirum.exceptions.DegirumException: [ERROR]Operation failed
Python postprocessor: forward: ‘list’ object has no attribute ‘get’ [AttributeError] in file ‘HailoDetectionYolo_0335a2b4eba1d2604f54de0e5f844f64.py’, function ‘forward’, line 88
dg_postprocess_client.cpp: 1009 [DG::PostprocessClient::forward]
When running model ‘yolov11n’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/home/anton/er.py”, line 42, in
inference_result = model(processed_frame)
^^^^^^^^^^^^^^^^^^^^^^
File “/home/anton/degirum_env/lib/python3.11/site-packages/degirum/log.py”, line 59, in wrap
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File “/home/anton/degirum_env/lib/python3.11/site-packages/degirum/model.py”, line 233, in call
return self.predict(data)
^^^^^^^^^^^^^^^^^^
File “/home/anton/degirum_env/lib/python3.11/site-packages/degirum/log.py”, line 59, in wrap
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File “/home/anton/degirum_env/lib/python3.11/site-packages/degirum/model.py”, line 224, in predict
res = list(self._predict_impl(source))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/anton/degirum_env/lib/python3.11/site-packages/degirum/model.py”, line 1206, in _predict_impl
raise DegirumException(
degirum.exceptions.DegirumException: Failed to perform model ‘yolov11n’ inference: [ERROR]Operation failed
Python postprocessor: forward: ‘list’ object has no attribute ‘get’ [AttributeError] in file ‘HailoDetectionYolo_0335a2b4eba1d2604f54de0e5f844f64.py’, function ‘forward’, line 88
dg_postprocess_client.cpp: 1009 [DG::PostprocessClient::forward]
When running model ‘yolov11n’

sorry maybe i wrote it badly, here the code , and such error "processed_frame, scale, pad_top, pad_left = resize_with_letterbox_image(frame, target_shape)
inference_result = model(processed_frame)

"

"degirum.exceptions.DegirumException: Image array shape ‘(1, 640, 640, 3)’ is not supported for ‘opencv’ image backend

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/home/anton/er.py”, line 55, in
inference_result = model(processed_frame)
^^^^^^^^^^^^^^^^^^^^^^
File “/home/anton/degirum_env/lib/python3.11/site-packages/degirum/log.py”, line 59, in wrap
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File “/home/anton/degirum_env/lib/python3.11/site-packages/degirum/model.py”, line 233, in call
return self.predict(data)
^^^^^^^^^^^^^^^^^^
File “/home/anton/degirum_env/lib/python3.11/site-packages/degirum/log.py”, line 59, in wrap
return f(*args, **kwargs)
^^^^^^^^^^^^^^^^^^
File “/home/anton/degirum_env/lib/python3.11/site-packages/degirum/model.py”, line 224, in predict
res = list(self._predict_impl(source))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/anton/degirum_env/lib/python3.11/site-packages/degirum/model.py”, line 1206, in _predict_impl
raise DegirumException(
degirum.exceptions.DegirumException: Failed to perform model ‘yolov11n’ inference: Image array shape ‘(1, 640, 640, 3)’ is not supported for ‘opencv’ image backend
"

Hi @An_ti11
If you are following this guide, you do not have to send the processed_frame. You can directly send the image path to inference.

Hello,

Thanks for your work on this guide !

I’m trying to use DeGirum with a basic yolov8 detection model, however, I have this error when trying to run my python script :

(.venv_hailo) p20c02@p20c02:~/rendu/degirum_tests$ python run_degirum.py 
 Running inference using 'yolov8m' on image source '/home/p20c02/rendu/COCO/small/000000000139.jpg'
degirum.exceptions.DegirumException: [ERROR]Operation failed
HailoRT Runtime Agent: Failed to create VDevice, status = HAILO_INVALID_OPERATION.
hailo_runtime_agent.cpp: 608 [DG::HailoRuntimeAgentImpl::Configure]
When running model 'yolov8m'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/p20c02/rendu/degirum_tests/run_degirum.py", line 25, in <module>
    inference_result = model(image_source)
  File "/home/p20c02/.venv_hailo/lib/python3.10/site-packages/degirum/log.py", line 59, in wrap
    return f(*args, **kwargs)
  File "/home/p20c02/.venv_hailo/lib/python3.10/site-packages/degirum/model.py", line 233, in __call__
    return self.predict(data)
  File "/home/p20c02/.venv_hailo/lib/python3.10/site-packages/degirum/log.py", line 59, in wrap
    return f(*args, **kwargs)
  File "/home/p20c02/.venv_hailo/lib/python3.10/site-packages/degirum/model.py", line 224, in predict
    res = list(self._predict_impl(source))
  File "/home/p20c02/.venv_hailo/lib/python3.10/site-packages/degirum/model.py", line 1206, in _predict_impl
    raise DegirumException(
degirum.exceptions.DegirumException: Failed to perform model 'yolov8m' inference: [ERROR]Operation failed
HailoRT Runtime Agent: Failed to create VDevice, status = HAILO_INVALID_OPERATION.
hailo_runtime_agent.cpp: 608 [DG::HailoRuntimeAgentImpl::Configure]
When running model 'yolov8m'

Here is the script :

import degirum as dg
import cv2
from pprint import pprint

inference_host_address = "@local"
zoo_url = 'assets'
token=''
device_type='HAILORT/HAILO8'

# set model name, and image source
model_name = "yolov8m"
image_source='/home/p20c02/rendu/COCO/small/000000000139.jpg'

# load AI model
model = dg.load_model(
    model_name=model_name,
    inference_host_address=inference_host_address,
    zoo_url=zoo_url,
    token=token,
    device_type=device_type,
)

# perform AI model inference on given image source
print(f" Running inference using '{model_name}' on image source '{image_source}'")
inference_result = model(image_source)

# Pretty print the detection results.
pprint(inference_result.results)
# Display the image with overlayed detection results.
cv2.imshow("AI Inference", inference_result.image_overlay)
cv2.waitKey(0)
cv2.destroyAllWindows()  # Close all OpenCV windows.

The json file yolov8m.json (stored in my assets/yolov8m folder with the PostProcessor class, labels_coco.json and yolov8m.hef) :

{
    "ConfigVersion": 10,
    "Checksum": "d6c4d0b9620dc2e5e215dfab366510a740fe86bf2c5d9bd2059a6ba3fe62ee63",
    "DEVICE": [
        {
            "DeviceType": "HAILO8",
            "RuntimeAgent": "HAILORT",
            "SupportedDeviceTypes": "HAILORT/HAILO8"
        }
    ],
    "PRE_PROCESS": [
        {
            "InputType": "Image",
            "InputN": 1,
            "InputH": 640,
            "InputW": 640,
            "InputC": 3,
            "InputPadMethod": "letterbox",
            "InputResizeMethod": "bilinear",                
            "InputQuantEn": true
        }
    ],
    "MODEL_PARAMETERS": [
        {
            "ModelPath": "yolov8m.hef"
        }
    ],
    "POST_PROCESS": [
        {
            "OutputPostprocessType": "Detection",
            "PythonFile": "HailoDetectionYolo.py",
            "OutputNumClasses": 80,
            "LabelsPath": "labels_coco.json",
            "OutputConfThreshold": 0.001
        }
    ]
}

Degirum sys info :

(.venv_hailo) p20c02@p20c02:~/rendu/Hailo-Application-Code-Examples-main/runtime/python/object_detection/hef_yolo$ degirum sys-info
Devices:
  HAILORT/HAILO8:
  - '@Index': 0
    Board Name: Hailo-8
    Device Architecture: HAILO8
    Firmware Version: 4.20.0
    ID: '0000:52:00.0'
    Part Number: HM218B1C2FAE
    Product Name: HAILO-8 AI ACC M.2 M KEY MODULE EXT TEMP
    Serial Number: "HLLWM2B223200047\x10HM218B1C2FAE"
  N2X/CPU:
  - '@Index': 0
  - '@Index': 1
  - '@Index': 2
  - '@Index': 3
  - '@Index': 4
  - '@Index': 5
  - '@Index': 6
  - '@Index': 7
  TFLITE/CPU:
  - '@Index': 0
  - '@Index': 1
  - '@Index': 2
  - '@Index': 3
  - '@Index': 4
  - '@Index': 5
  - '@Index': 6
  - '@Index': 7
Software Version: 0.15.3

Have a great day !

Cordially,

@shashi
Hi,
I successfully ran yolov11 and yolov8 pretrained models with the help of above solution. When I am trying to run yolov8 custom model, the inference result is an empty list.
My custom model was prepared from pytorch to onnx to hef.
Please let me know if there is any process or steps to prepare a custom model that works with PySdk for inference.

Hi @manasa
Can you share the model json and the code snippet?

Json file is:

{
“ConfigVersion”: 10,
“Checksum”: “80752ca746bba42db3056d4b53f6c401bfcf930cf3bd5f82ae66a07a68dfa5ec”,
“DEVICE”: [
{
“DeviceType”: “HAILO8L”,
“RuntimeAgent”: “HAILORT”,
“SupportedDeviceTypes”: “HAILORT/HAILO8L”
}
],
“PRE_PROCESS”: [
{
“InputType”: “Image”,
“InputN”: 1,
“InputH”: 640,
“InputW”: 640,
“InputC”: 3,
“InputPadMethod”: “letterbox”,
“InputResizeMethod”: “bilinear”,
“InputQuantEn”: true
}
],
“MODEL_PARAMETERS”: [
{
“ModelPath”: “yolov8m.hef”
}
],
“POST_PROCESS”: [
{
“OutputPostprocessType”: “Detection”,
“PythonFile”: “HailoDetectionYolo.py”,
“OutputNumClasses”: 7,
“LabelsPath”: “popcorn.json”,
“OutputConfThreshold”: 0.3
}
]
}

Inference code is:

import degirum as dg
from pprint import pprint
model = dg.load_model(
model_name=‘yolov8m’,
inference_host_address=‘@local’,
zoo_url=‘/home/jk/manasa’
)
print(“Model Info:”, dir(model))
print(“Model Labels:”, model.output_class_set)
print(“Input Shape:”, model.input_shape)
inference_result = model(‘/home/jk/frame_8250.jpg’)
pprint(inference_result.results)

I followed the above steps whatever you shared. I got for pre-trained model but for custom trained model I got empty set. Can you please help me out for custom trained model?

Hi
Help me!
My error:

(degirum_env) RPiAI@Loitran:~/workspace/hailo_examples/py_hailo8l $ python test_detection.py 
Traceback (most recent call last):
  File "/home/RPiAI/workspace/hailo_examples/py_hailo8l/test_detection.py", line 5, in <module>
    model = dg.load_model(
            ^^^^^^^^^^^^^^
  File "/home/RPiAI/workspace/hailo_examples/degirum_env/lib/python3.11/site-packages/degirum/__init__.py", line 220, in load_model
    return zoo.load_model(model_name, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/RPiAI/workspace/hailo_examples/degirum_env/lib/python3.11/site-packages/degirum/log.py", line 59, in wrap
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/RPiAI/workspace/hailo_examples/degirum_env/lib/python3.11/site-packages/degirum/zoo_manager.py", line 266, in load_model
    model = self._zoo.load_model(model_name)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/RPiAI/workspace/hailo_examples/degirum_env/lib/python3.11/site-packages/degirum/log.py", line 59, in wrap
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/RPiAI/workspace/hailo_examples/degirum_env/lib/python3.11/site-packages/degirum/_zoo_accessor.py", line 623, in load_model
    assets = self._get_model_assets(model, True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/RPiAI/workspace/hailo_examples/degirum_env/lib/python3.11/site-packages/degirum/_zoo_accessor.py", line 576, in _get_model_assets
    model_info = self._cloud_server_request(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/RPiAI/workspace/hailo_examples/degirum_env/lib/python3.11/site-packages/degirum/log.py", line 59, in wrap
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/home/RPiAI/workspace/hailo_examples/degirum_env/lib/python3.11/site-packages/degirum/_zoo_accessor.py", line 494, in _cloud_server_request
    raise DegirumException(details) from None
degirum.exceptions.DegirumException: 404 Client Error: Not Found for url: https://hub.degirum.com/zoo/v1/public/models/home/RPiAI/workspace/hailo_examples/pySDK/my_models/yolov11m/info
(degirum_env) RPiAI@Loitran:~/workspace/hailo_examples/py_hailo8l $ 

my code:

import degirum as dg
from pprint import pprint

model_zoo = '/home/RPiAI/workspace/hailo_examples/pySDK/my_models'
model = dg.load_model(
    model_name='yolov11m',
    inference_host_address='@local',
    zoo_url=model_zoo
)

inference_result = model('/home/RPiAI/Downloads/Cat.jpg')

pprint(inference_result.results)

my yolov11m.json:

{
    "ConfigVersion": 10,
    "DEVICE": [
        {
            "DeviceType": "HAILO8L",
            "RuntimeAgent": "HAILORT",
            "SupportedDeviceTypes": "HAILORT/HAILO8L"
        }
    ],
    "PRE_PROCESS": [
        {
            "InputType": "Image",
            "InputN": 1,
            "InputH": 640,
            "InputW": 640,
            "InputC": 3,
            "InputPadMethod": "letterbox",
            "InputResizeMethod": "bilinear",                
            "InputQuantEn": true
        }
    ],
    "MODEL_PARAMETERS": [
        {
            "ModelPath": "yolov11m.hef"
        }
    ],
    "POST_PROCESS": [
        {
            "OutputPostprocessType": "Detection",
            "PythonFile": "HailoDetectionYolo.py",
            "OutputNumClasses": 80,
            "LabelsPath": "labels_coco.json",
            "OutputConfThreshold": 0.3           
        }
    ]
}

I use Hailo 8L
I not good English. Plss help me! thanks!

Hi @Loi_Tran
Please add one more line to the JSON below the ConfigVersion line:
"Checksum": "",