Skip to content

[Relay] Support resize in the ONNX conversion - #8455

Merged
trevor-m merged 5 commits into
apache:mainfrom
schilkunda-amba:relay_to_onnx_resize
Jul 21, 2021
Merged

trevor-m merged 5 commits into
apache:mainfrom
schilkunda-amba:relay_to_onnx_resize

Conversation

@schilkunda-amba

Copy link
Copy Markdown
Contributor
  • Added support for resize2d op
  • Added unit test

* Added support for resize2d op
* Added unit test
* Fixed formatting errors
@comaniac comaniac changed the title [Relay to Onnx conversion][Resize] [Relay] Support resize in the ONNX conversion Jul 12, 2021

@comaniac comaniac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also support resize in other dimensions?

@trevor-m trevor-m left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @schilkunda-amba! Some small comments

Comment thread python/tvm/contrib/target/onnx.py
Comment thread tests/python/contrib/test_onnx.py
* Fixed issue in resize conversion: round maps to round_preferc_ceil
* Updated resize unit test to test for coordinate transform mode and
round
* Known issue: Does not match for (NN, align_corners) and Cubic
@schilkunda-amba

Copy link
Copy Markdown
Contributor Author

Can we also support resize in other dimensions?

Sure, I will look into it.

@schilkunda-amba

Copy link
Copy Markdown
Contributor Author

@comaniac @trevor-m
I have made the changes (catch error using else and updating the test for coord trans and rounding method). I see that it the conversion fails (as in not identical) for certain cases.

I had to add the following:
if (i == "nearest_neighbor" and j == "align_corners") or (i == "cubic" and j in ["half_pixel", "align_corners"]):

Should I use the discussion forum to debug this?

@comaniac

Copy link
Copy Markdown
Contributor

@mbrookhart could you help take a look if you got a chance?

@mbrookhart mbrookhart left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me. I am curious what the use case for this pass is :)

@schilkunda-amba

Copy link
Copy Markdown
Contributor Author

This looks fine to me. I am curious what the use case for this pass is :)

@mbrookhart Here is the PR for this: https://discuss.tvm.apache.org/t/rfc-relay-to-onnx/6101

The issue I am facing is relay operator resize2d doesn't faithfully convert to onnx operator Resize when method = nearest_neighbor and coordinate_transformation_mode = half_pixel

@mbrookhart

Copy link
Copy Markdown
Contributor

Interesting. We run this onnx file in CI and make sure it imports correctly: https://github.com/onnx/onnx/blob/v1.6.0/onnx/backend/test/data/node/test_resize_upsample_sizes_nearest_ceil_half_pixel/model.onnx

Maybe you could import it, and then re-export the relay, and compare the protobuf you get with the original?

@schilkunda-amba

Copy link
Copy Markdown
Contributor Author

Interesting. We run this onnx file in CI and make sure it imports correctly: https://github.com/onnx/onnx/blob/v1.6.0/onnx/backend/test/data/node/test_resize_upsample_sizes_nearest_ceil_half_pixel/model.onnx

Maybe you could import it, and then re-export the relay, and compare the protobuf you get with the original?

Thanks. Let me give it a try.

@comaniac comaniac left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. cc @trevor-m

@trevor-m trevor-m left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trevor-m
trevor-m merged commit 789ab1f into apache:main Jul 21, 2021
@schilkunda-amba

Copy link
Copy Markdown
Contributor Author

Thanks @trevor-m @comaniac

@schilkunda-amba
schilkunda-amba deleted the relay_to_onnx_resize branch July 21, 2021 21:19
ylc pushed a commit to ylc/tvm that referenced this pull request Sep 29, 2021
* [Relay to Onnx]

* Added support for resize2d op
* Added unit test

* [Relay to Onnx][Resize]

* Fixed formatting errors

* [Relay to Onnx][Resize]

* Fixed issue in resize conversion: round maps to round_preferc_ceil
* Updated resize unit test to test for coordinate transform mode and
round
* Known issue: Does not match for (NN, align_corners) and Cubic

* * Fixed formatting errors

* * Fixed some more formatting errors
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
* [Relay to Onnx]

* Added support for resize2d op
* Added unit test

* [Relay to Onnx][Resize]

* Fixed formatting errors

* [Relay to Onnx][Resize]

* Fixed issue in resize conversion: round maps to round_preferc_ceil
* Updated resize unit test to test for coordinate transform mode and
round
* Known issue: Does not match for (NN, align_corners) and Cubic

* * Fixed formatting errors

* * Fixed some more formatting errors
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.

4 participants