I have custom classification model with 6 classes architecture - resnext50_32x4d I have converted model to onnx and using that onnx converted to .hef using DFC (hailo-dataflow-compiler-3.29.0 , python - 3.10). After inferencing using ONNX model I am getting following expected output - [ 5.7061105 -15.642113 -15.150752 -15.781985 -14.646156 -4.8654194]
hef output - [-12.953751, -12.054185, -13.133664, -14.03323 , -12.234098,13.313578] for same images with same preprocessing steps.
I amusing following code to convert the model let me know if I am missing any step -
import tensorflow as tf
import os
import numpy as np
import cv2
from hailo_sdk_client import ClientRunner
Define model and hardware parameters
chosen_hw_arch = “hailo8l” # Hardware architecture for Hailo8l chip
onnx_model_name = “classification1” # Model name for ONNX model
onnx_path = “classification1.onnx” # Path to ONNX model
hailo_model_har_name = f"./{onnx_model_name}_hailo_model.har"
quantized_model_har_path = f"./{onnx_model_name}_quantized_model.har"
file_name = f"./{onnx_model_name}.hef"
Parse the ONNX model to Hailo format
runner = ClientRunner(hw_arch=chosen_hw_arch)
hn, npz = runner.translate_onnx_model(
onnx_path,
onnx_model_name,
start_node_names=[“Conv_0”], # Input node name
end_node_names=[“Gemm_121”], # Output node name
net_input_shapes={“Conv_0”: [1, 3, 448, 352]}, # Input shape
)
runner.save_har(hailo_model_har_name) # Save the HAR model
Prepare images for model optimization
IMAGES_TO_VISUALIZE = 5
image_dir = ‘./data’ # Folder containing images
image_files = [f for f in os.listdir(image_dir) if f.endswith((‘.png’, ‘.jpg’, ‘.jpeg’))]
images =
Load and preprocess images
for image_file in image_files:
img_path = os.path.join(image_dir, image_file)
img = cv2.imread(img_path)
img_resized = cv2.resize(img, (352, 448)) # Resize to expected input shape
img_rgb = cv2.cvtColor(img_resized, cv2.COLOR_BGR2RGB) # Convert BGR to RGB
images.append(img_rgb)
Convert images list to NumPy array
images_array = np.array(images)
Load and optimize the HAR model
runner = ClientRunner(har=hailo_model_har_name, hw_arch=chosen_hw_arch)
runner.load_model_script(“resnext50_32x4d.alls”) # Load optimization script
runner.optimize(images_array) # Optimize model with sample images
runner.save_har(quantized_model_har_path) # Save quantized HAR model
Compile the quantized HAR model
runner = ClientRunner(har=quantized_model_har_path, hw_arch=chosen_hw_arch)
hef = runner.compile() # Compile model to HEF format
Save the compiled HEF file
with open(file_name, “wb”) as f:
f.write(hef)
print(“Model processing complete. Compiled HEF saved at:”, file_name)
resnext50_32x4d.alls----------------------
normalization = normalization([123.675, 116.28, 103.53], [58.395, 57.12, 57.375])
pre_quantization_optimization(equalization, policy=disabled)