**I’ve tried these steps for converting ONNX model to HEF. Do i suppose to run this command. If yes then
- how will i get nanodet.alls?
- Where do i need to use nanodet_nms_config.json **
hailo optimize nanodet.har --calib-set-path calib_set.npy --model-script nanodet.alls
Steps to convert onnx to HEF
1. First convert onnx to har file using this command:
hailo parser onnx nanodet.onnx --hw-arch=hailo8l
Use this script to get calib_set.npy, will be use for optimization
(.venv) taruna@taruna-desktop:~/Hailo/models
$ cat create_calib_set.py
import numpy as np
import os
from PIL import Image
# Define the folder containing images
image_folder = '/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_tutorials/data'
images = []
# Process each image in the folder
for img_name in os.listdir(image_folder):
# Only process files with a .jpg extension
if img_name.lower().endswith('.jpg'):
img_path = os.path.join(image_folder, img_name)
# Open the image, resize to 64x64, and convert to grayscale
#img = Image.open(img_path).resize((64, 64)).convert('L') # 'L' mode for grayscale
img = Image.open(img_path).resize((416, 416))
img_array = np.array(img)
# Add a channel dimension to match the expected shape (64, 64, 1)
# img_array = np.expand_dims(img_array, axis=-1)
images.append(img_array)
# Convert the list of images to a NumPy array
calib_set = np.array(images)
# Save the calibration dataset to a .npy file
np.save('calib_set.npy', calib_set)
print("Calibration dataset saved as 'calib_set.npy'")
Optimize .har file
(.venv) taruna@taruna-desktop:~/Hailo/models
$ hailo optimize nanodet.har --calib-set-path calib_set.npy
[info] Current Time: 17:18:15, 11/18/24
[info] CPU: Architecture: x86_64, Model: 12th Gen Intel(R) Core™ i7-12700, Number Of Cores: 20, Utilization: 0.2%
[info] Memory: Total: 23GB, Available: 3GB
[info] System info: OS: Linux, Kernel: 6.8.0-40-generic
[info] Hailo DFC Version: 3.29.0
[info] HailoRT Version: Not Installed
[info] PCIe: No Hailo PCIe device was found
[info] Running hailo optimize nanodet.har --calib-set-path calib_set.npy
[info] For NMS architecture yolov5 the default engine is auto. For other engine please use the 'engine' flag in the nms_postprocess model script command. If the NMS has been added during parsing, please parse the model again without confirming the addition of the NMS, and add the command manually with the desired engine.
[info] Using the default score threshold of 0.3 (range is [0-1], where 1 performs maximum suppression) and IoU threshold of 1.0 (range is [0-1], where 0 performs maximum suppression).
Changing the values is possible using the nms_postprocess model script command.
[info] The activation function of layer nanodet/conv28 was replaced by a Sigmoid
[info] The activation function of layer nanodet/conv31 was replaced by a Sigmoid
[info] The activation function of layer nanodet/conv34 was replaced by a Sigmoid
Traceback (most recent call last):
File “/home/taruna/Hailo/.venv/bin/hailo”, line 8, in
sys.exit(main())
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_client/tools/cmd_utils/main.py”, line 111, in main
ret_val = client_command_runner.run()
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_client/tools/cmd_utils/base_utils.py”, line 68, in run
return self._run(argv)
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_client/tools/cmd_utils/base_utils.py”, line 89, in _run
return args.func(args)
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_client/tools/optimize_cli.py”, line 113, in run
self._runner.optimize_full_precision(calib_data=dataset)
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_common/states/states.py”, line 16, in wrapped_func
return func(self, *args, **kwargs)
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_client/runner/client_runner.py”, line 1996, in optimize_full_precision
self._optimize_full_precision(calib_data=calib_data, data_type=data_type)
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_client/runner/client_runner.py”, line 1999, in _optimize_full_precision
self._sdk_backend.optimize_full_precision(calib_data=calib_data, data_type=data_type)
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/sdk_backend.py”, line 1497, in optimize_full_precision
model, params = self._apply_model_modification_commands(model, params, update_model_and_params)
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/sdk_backend.py”, line 1388, in _apply_model_modification_commands
model, params = command.apply(model, params, hw_consts=self.hw_arch.consts)
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/script_parser/nms_postprocess_command.py”, line 387, in apply
pp_creator = create_nms_postprocess(
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_client/tools/core_postprocess/nms_postprocess.py”, line 1767, in create_nms_postprocess
pp_creator.prepare_hn_and_weights(hw_consts, engine, dfl_on_nn_core=dfl_on_nn_core)
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_client/tools/core_postprocess/nms_postprocess.py”, line 1592, in prepare_hn_and_weights
self._add_feature_multiplier_layer()
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_client/tools/core_postprocess/nms_postprocess.py”, line 1505, in _add_feature_multiplier_layer
yolo_power_table = feature_multiplier_layer.init_power_table(
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_common/hailo_nn/hn_layers/feature_multiplier.py”, line 134, in init_power_table
self.validate_recipe(recipe)
File “/home/taruna/Hailo/.venv/lib/python3.10/site-packages/hailo_sdk_common/hailo_nn/hn_layers/feature_multiplier.py”, line 108, in validate_recipe
raise Exception(
Exception: Each output in recipe should contains same number of tuples as output shape features at feature multiplier layer nanodet/feature_multiplier28