Skip to content

Handle empty optional ONNX inputs in shape parsing#1507

Open
niteshg97 wants to merge 3 commits into
fastmachinelearning:mainfrom
niteshg97:main
Open

Handle empty optional ONNX inputs in shape parsing#1507
niteshg97 wants to merge 3 commits into
fastmachinelearning:mainfrom
niteshg97:main

Conversation

@niteshg97

Copy link
Copy Markdown
Contributor

Summary

Fixes #1266.

In ONNX, optional inputs that are not provided are represented by an empty string (""). For example, a Resize node can have inputs like : ['Quant_0_out0', '', 'Resize_0_param0']

where the second entry corresponds to the optional ROI input.

At the moment, get_input_shape() attempts to resolve the shape for every input, including the empty placeholder. Since an empty string does not correspond to a valid tensor, this results in,

RuntimeError: Could not find the shape for input

This change simply skips empty input placeholders while keeping the existing behavior unchanged for valid input names. If a non empty input is missing its shape, the same error is still raised.

Changes

  • Ignore empty input placeholders in get_input_shape().
  • Update the docstring to clarify that shapes are returned only for non empty inputs.
  • Add a regression test for a Resize node with the optional ROI input omitted.

Testing

pytest test/pytest/test_onnx_to_hls.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hls4ml config_from_onnx_model fails when using a Resize node with no ROI (Brevitas -> QONNX)

1 participant