How to convert custom yolov7_tiny model into hef

I have a custom yolov7_tiny model (with custom dataset and classes) converted to onnx. Currently I’m trying to convert it into a hef file to run on the Hailo8 board. I’m trying to convert it on my x86 pc (without hailo installed in it) using dfc that hailo model zoo requires. I created a script with code provided here: https://www.macnica.co.jp/en/business/semiconductor/articles/hailo/144843/, and got this error message while trying to run the script to convert my model:

python dfc_script.py  1 ✘  4s   hailo_model_zoo 
[info] Translation started on ONNX model yolov7_tiny
[info] Restored ONNX model yolov7_tiny (completion time: 00:00:00.07)
[info] Extracted ONNXRuntime meta-data for Hailo model (completion time: 00:00:00.27)
[info] Simplified ONNX model for a parsing retry attempt (completion time: 00:00:00.64)
Traceback (most recent call last):
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py”, line 220, in translate_onnx_model
parsing_results = self._parse_onnx_model_to_hn(
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py”, line 300, in _parse_onnx_model_to_hn
return self.parse_model_to_hn(
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py”, line 340, in parse_model_to_hn
converter = ONNXConverter(
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/model_translator/onnx_translator/onnx_translator.py”, line 170, in init
super().init(
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/model_translator/edge_nn_translator.py”, line 27, in init
super().init(graph, start_node_names, end_node_names)
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/model_translator/translator.py”, line 51, in init
self._calculate_valid_subgraph_scope()
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/model_translator/translator.py”, line 388, in _calculate_valid_subgraph_scope
current_vertex.in_valid_subgraph = True
AttributeError: ‘NoneType’ object has no attribute ‘in_valid_subgraph’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “dfc_script.py”, line 22, in
hn, npz = runner.translate_onnx_model(onnx_path, model_name, start_node_names=[start_node], end_node_names=end_node, net_input_shapes=input_shape)
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_common/states/states.py”, line 16, in wrapped_func
return func(self, *args, **kwargs)
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/runner/client_runner.py”, line 1158, in translate_onnx_model
parser.translate_onnx_model(
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py”, line 260, in translate_onnx_model
parsing_results = self._parse_onnx_model_to_hn(
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py”, line 300, in _parse_onnx_model_to_hn
return self.parse_model_to_hn(
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py”, line 340, in parse_model_to_hn
converter = ONNXConverter(
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/model_translator/onnx_translator/onnx_translator.py”, line 170, in init
super().init(
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/model_translator/edge_nn_translator.py”, line 27, in init
super().init(graph, start_node_names, end_node_names)
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/model_translator/translator.py”, line 51, in init
self._calculate_valid_subgraph_scope()
File “/run/media/issatays/ADATAExternal/GitStuffD/hailo_model_zoo/.venv/lib/python3.8/site-packages/hailo_sdk_client/model_translator/translator.py”, line 388, in _calculate_valid_subgraph_scope
current_vertex.in_valid_subgraph = True
AttributeError: ‘NoneType’ object has no attribute ‘in_valid_subgraph’

How can I tackle this issue?

Hi @isatay,
Can you provide the code you used for conversion and the ONNX you used? You can send the ONNX via DM.

Regards,

@isatay - Another thing to check is that the end or start nodes that are specified in the yaml file exist in the actual model file (ONNX). If it’s not, you will need to update the yaml to match the end nodes of your model.

I exported the onnx model using the export.py script found in WongKinYiu’s yolov7 git repository (yolov7/export.py at main · WongKinYiu/yolov7 · GitHub), which doesn’t seem to work with my script to convert onnx to hailo’s hef

By yaml file you mean the one found in hailo_model_zoo/cfg/network/yolov7_tiny.yaml?

1 Like

ok, so I managed to compile a .hef file from my onnx model, but now when I try to run it on my sbc with hailo8 installed, it gives me an “invalid hef file” error. I’m assuming that’s because of hailort and dfc incompatability, since I’m using dfc version 3.28, while hailort version is 1.17.0. So I wanted to check with you which dfc version is compatible with hailort 1.17.0?

ok, so I managed to compile a .hef file from my onnx model using the solution from this thread (Convert Yolo Pytorch model to HEF for Raspberry Pi 5 with Hailo8L - #4 by Omer), but now when I try to run it on my sbc with hailo8 installed, it gives me an “invalid hef file” error. I’m assuming that’s because of hailort and dfc incompatability, since I’m using dfc version 3.28, while hailort version is 1.17.0. So I wanted to check with you which dfc version is compatible with hailort 1.17.0?