Hailo Emulator cannot run with DFC >=3.26

Hi,

I am trying to run the Hailo Emulator using the data from the tutorial with the code below. It works with DFC 3.25, but with 3.26 and later it gives an error and doesn’t work.
How should I fix my code?

Code:

from hailo_sdk_client import ClientRunner

model_name = 'resnet_v1_18'
ckpt_path = '../models/resnet_v1_18.ckpt'

start_node = 'resnet_v1_18/conv1/Pad'
end_node = 'resnet_v1_18/predictions/Softmax'

chosen_hw_arch = 'hailo8'
runner = ClientRunner(hw_arch=chosen_hw_arch)
hn, npz = runner.translate_tf_model(ckpt_path, model_name, start_node_names=[start_node], end_node_names=[end_node])

from hailo_sdk_client import InferenceContext

import numpy as np
import glob
import cv2

TOTAL = len(glob.glob("../data/*.jpg"))

input_shape = (1, 224, 224, 3)
input_dtype = np.float32
input_data_0 = np.zeros(
    (TOTAL, input_shape[1], input_shape[2], input_shape[3])
).astype(input_dtype)

files = sorted(glob.glob("../data/*.jpg"))
for i, file in enumerate(files):
    img = cv2.imread(file)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    image = (
        cv2.resize(img, (input_shape[1], input_shape[2]))
        .astype(input_dtype)
    )
    input_data_0[i] = ((image - [123.675, 116.28, 103.53]) / [58.395, 57.12, 57.375])


# Infer an image with the Hailo Emulator
with runner.infer_context(InferenceContext.SDK_FP_OPTIMIZED) as ctx:
    result = runner.infer(ctx, input_data_0)
    print(np.argmax(result, axis=1))
    np.save('label.npy', result)

Messages:

Traceback (most recent call last):
  File "/work/venv/lib/python3.10/site-packages/hailo_tutorials/notebooks/tmp.py", line 40, in <module>
    result = runner.infer(ctx, input_data_0)
  File "/work/venv/lib/python3.10/site-packages/hailo_sdk_common/states/states.py", line 16, in wrapped_func
    return func(self, *args, **kwargs)
  File "/work/venv/lib/python3.10/site-packages/hailo_sdk_client/runner/client_runner.py", line 299, in infer
    return self._infer_emulator(data, data_count, batch_size, context)
  File "/work/venv/lib/python3.10/site-packages/hailo_sdk_client/runner/client_runner.py", line 318, in _infer_emulator
    return self._sdk_backend.acceleras_inference(dataset=dataset,
  File "/work/venv/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/sdk_backend.py", line 977, in acceleras_inference
    model = self.build_acceleras_model(context)
  File "/work/venv/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/sdk_backend.py", line 750, in build_acceleras_model
    hn_data = self.get_hn_fp_dict()
  File "/work/venv/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/sdk_backend.py", line 120, in get_hn_fp_dict
    model_copy = self.fp_model.from_parsed_hn(self.fp_model.to_hn(self.fp_model.name, json_dump=False))
AttributeError: 'NoneType' object has no attribute 'from_parsed_hn'

Hi, it seems that your virtual-environment have a mixup of version, if you start a clean environment of 3.29, does the error persist?

Hi, thank you for your swift reply.
I think 3.28 is the latest version I can get.

I cleaned the environment and installed only DFC 3.28, but I still get the same error.

Oh… silly me… you forgot to optimize the model. Please add:
runner.optimize(input_data_0)
right before the infer, it will work :wink:

1 Like

Hi, thank you for your advice.
I was able to confirm that the emulator works.

Regards,