Parsing ONNX to HAR problem

Hello Community,
I am trying to parse ONNX to HAR, but I couldnt solve it for several days.

The kernel features are set to 384, but the input features detected are 383.

You can download onnx files (opset 17):

Here is my codes:
from hailo_sdk_client import ClientRunner
onnx_model_name = ‘vits17’
onnx_path = ‘saved_model/vits17.onnx’
runner = ClientRunner(hw_arch=‘hailo8’)
hn, npz = runner.translate_onnx_model(onnx_path, onnx_model_name)


[info] Translation started on ONNX model vits17
[info] Restored ONNX model vits17 (completion time: 00:00:00.22)
[info] Extracted ONNXRuntime meta-data for Hailo model (completion time: 00:00:03.18)
[info] Simplified ONNX model for a parsing retry attempt (completion time: 00:00:10.42)

UnsupportedModelError Traceback (most recent call last)
File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py:179, in Parser.translate_onnx_model(self, model, net_name, start_node_names, end_node_names, net_input_shapes, augmented_path, disable_shape_inference, disable_rt_metadata_extraction)
178 try:
→ 179 parsing_results = self._parse_onnx_model_to_hn(onnx_model, valid_net_name, start_node_names,
180 end_node_names, net_input_shapes,
181 disable_shape_inference)
183 except Exception as e:

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py:237, in Parser._parse_onnx_model_to_hn(self, onnx_model, net_name, start_node_names, end_node_names, net_input_shapes, disable_shape_inference)
235 self._logger.warning(f’ONNX shape inference failed: {str(e)}')
→ 237 return self.parse_model_to_hn(onnx_model, None, net_name, start_node_names, end_node_names,
238 nn_framework=NNFramework.ONNX, output_shapes=output_shapes)

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py:263, in Parser.parse_model_to_hn(self, model, values, net_name, start_node_names, end_node_names, nn_framework, output_shapes)
261 raise BackendRuntimeException(f’Unsupported NN framework {nn_framework}')
→ 263 fuser = HailoNNFuser(converter.convert_model(), net_name, converter.end_node_names)
264 hailo_nn = fuser.convert_model()

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_client/model_translator/translator.py:85, in HailoNNConverter.convert_model(self)
84 self._handle_inner_product_matmul()
—> 85 self._calculate_shapes(validate_shapes=False)
86 self._add_output_layers()

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_client/model_translator/onnx_translator/onnx_translator.py:110, in ONNXConverter._calculate_shapes(self, validate_shapes)
109 self._update_meta_graph()
→ 110 self._layers_graph.calculate_shapes(meta_edges_graph=self._meta_graph, validate_shapes=validate_shapes)

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_common/hailo_nn/hailo_nn.py:634, in HailoNN.calculate_shapes(self, meta_edges_graph, validate_shapes)
632 layer.output_copies = self.get_number_of_successors(layer)
→ 634 layer.update_output_shapes(hn_stage=self.net_params.stage, validate_shapes=validate_shapes)

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_common/hailo_nn/hn_layers/ew_mult.py:157, in EWMultLayer.update_output_shapes(self, **kwargs)
156 if len(self._input_list) != 2:
→ 157 raise UnsupportedModelError(f’{self.full_name_msg} expects 2 inputs but found {len(self._input_list)}')
158 input0_shape = self.pred_layer_output_shape(self._input_list[0], True)

UnsupportedModelError: ew mult layer ew_mult1 (translated from /blocks.0/attn/Mul) expects 2 inputs but found 1

During handling of the above exception, another exception occurred:

UnsupportedModelError Traceback (most recent call last)
Cell In [6], line 2
1 runner = ClientRunner(hw_arch=‘hailo8’)
----> 2 hn, npz = runner.translate_onnx_model(onnx_path, onnx_model_name)

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_common/states/states.py:16, in allowed_states..wrap..wrapped_func(self, *args, **kwargs)
13 if self._state not in states:
14 raise InvalidStateException("The execution of {} is not available under the state: "
15 “{}”.format(func.name, self._state.value))
—> 16 return func(self, *args, **kwargs)

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_client/runner/client_runner.py:876, in ClientRunner.translate_onnx_model(self, model, net_name, start_node_names, end_node_names, net_input_shapes, augmented_path, disable_shape_inference, disable_rt_metadata_extraction)
844 “”“DFC API for parsing an ONNX model. This creates a runner with loaded HN (model) and
845 parameters.
846
(…)
873 tuple: The first item is the HN JSON as a string. The second item is the params dict.
874 “””
875 parser = Parser()
→ 876 parser.translate_onnx_model(model=model, net_name=net_name, start_node_names=start_node_names,
877 end_node_names=end_node_names, net_input_shapes=net_input_shapes,
878 augmented_path=augmented_path, disable_shape_inference=disable_shape_inference,
879 disable_rt_metadata_extraction=disable_rt_metadata_extraction)
881 return self._finalize_parsing(parser.return_data)

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py:211, in Parser.translate_onnx_model(self, model, net_name, start_node_names, end_node_names, net_input_shapes, augmented_path, disable_shape_inference, disable_rt_metadata_extraction)
208 milestone = self._format_time_milestone(start_time)
209 self._logger.info(f’Simplified ONNX model for a parsing retry attempt (completion time: {milestone})‘)
→ 211 parsing_results = self._parse_onnx_model_to_hn(simplified_model, valid_net_name,
212 start_node_names, end_node_names,
213 net_input_shapes,
214 disable_shape_inference)
216 milestone = self._format_time_milestone(start_time)
217 self._logger.info(f’Translation completed on ONNX model {valid_net_name} ’
218 f’(completion time: {milestone})')

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py:237, in Parser._parse_onnx_model_to_hn(self, onnx_model, net_name, start_node_names, end_node_names, net_input_shapes, disable_shape_inference)
234 except Exception as e:
235 self._logger.warning(f’ONNX shape inference failed: {str(e)}')
→ 237 return self.parse_model_to_hn(onnx_model, None, net_name, start_node_names, end_node_names,
238 nn_framework=NNFramework.ONNX, output_shapes=output_shapes)

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_client/sdk_backend/parser/parser.py:263, in Parser.parse_model_to_hn(self, model, values, net_name, start_node_names, end_node_names, nn_framework, output_shapes)
260 else:
261 raise BackendRuntimeException(f’Unsupported NN framework {nn_framework}')
→ 263 fuser = HailoNNFuser(converter.convert_model(), net_name, converter.end_node_names)
264 hailo_nn = fuser.convert_model()
265 hailo_nn.validate_stage(HnStage.HN)

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_client/model_translator/translator.py:85, in HailoNNConverter.convert_model(self)
83 self._handle_const_input_broadcast()
84 self._handle_inner_product_matmul()
—> 85 self._calculate_shapes(validate_shapes=False)
86 self._add_output_layers()
87 self._handle_fused_layers()

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_client/model_translator/onnx_translator/onnx_translator.py:110, in ONNXConverter._calculate_shapes(self, validate_shapes)
108 def _calculate_shapes(self, validate_shapes=True):
109 self._update_meta_graph()
→ 110 self._layers_graph.calculate_shapes(meta_edges_graph=self._meta_graph, validate_shapes=validate_shapes)

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_common/hailo_nn/hailo_nn.py:627, in HailoNN.calculate_shapes(self, meta_edges_graph, validate_shapes)
625 graph = nx.lexicographical_topological_sort(meta_edges_graph) if meta_edges_graph else self.stable_toposort()
626 for layer in graph:
→ 627 self.update_input_shapes_from_predecessors(layer)
628 if layer.op in [LayerType.feature_splitter, LayerType.row_splitter, LayerType.width_splitter, LayerType.demux,
629 LayerType.feature_multiplier, LayerType.precision_splitter] or layer.op == LayerType.format_conversion and layer.is_nv_converter():
630 layer.output_copies = 1

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_common/hailo_nn/hailo_nn.py:668, in HailoNN.update_input_shapes_from_predecessors(self, layer)
666 self.add_edge(pred, layer, out_shape=pred_output_shape, in_shape=layer.reshape_input(pred_output_shape))
667 assert all(shape != for shape in input_shapes)
→ 668 layer.input_shapes = input_shapes

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_common/hailo_nn/hn_layers/layer.py:505, in Layer.input_shapes(self, input_shapes)
502 elif any(not isinstance(shape, list) for shape in input_shapes):
503 raise UnsupportedModelError(f’Unexpected input_shapes at {self.full_name_msg}, input_shapes={input_shapes} ’
504 f’(type={type(input_shapes)})')
→ 505 self.set_input_shapes(input_shapes)

File /local/workspace/hailo_virtualenv/lib/python3.8/site-packages/hailo_sdk_common/hailo_nn/hn_layers/conv2d.py:511, in Conv2DLayer.set_input_shapes(self, input_shapes, validate)
507 # We don’t validate that the feature dimensions are equal in case of conv with ew_add.
508 # In that case, there may be two different input_features (one for each input).
509 # The input features are validated in _calc_conv_ew_add_output_shape.
510 if input_features != self.kernel_shape[2] * calculated_groups:
→ 511 raise UnsupportedModelError(
512 f"Invalid kernel shape for {self.full_name_msg}.\nEither the input shape "
513 f"doesn’t match the kernel shape, or the calculated groups number doesn’t "
514 f"match the expected ratio between kernel shape and input shape.\n"
515 f"Kernel features: {self.kernel_shape[2]} Input features: {input_features} "
516 f"Groups: {calculated_groups}"
517 )
519 self.groups = calculated_groups

UnsupportedModelError: Invalid kernel shape for base conv layer base_conv15 (translated from /depth_head/projects.0/Conv).
Either the input shape doesn’t match the kernel shape, or the calculated groups number doesn’t match the expected ratio between kernel shape and input shape.
Kernel features: 384 Input features: 383 Groups: 0

Hi @changjoo.lee,
I can tell you that we are working on adding this model the model-zoo officially. We will update once it’s there.

Thank you very much for your service :slight_smile: