Skip to content

[Relax][Onnx][Resize] Fix ROI values when tensor ROI is Empty pass node Constant#18691

Merged
tlopex merged 1 commit into
apache:mainfrom
locnd182644:Onnx/Resize
Jan 30, 2026
Merged

[Relax][Onnx][Resize] Fix ROI values when tensor ROI is Empty pass node Constant#18691
tlopex merged 1 commit into
apache:mainfrom
locnd182644:Onnx/Resize

Conversation

@locnd182644

Copy link
Copy Markdown
Contributor

This PR fix ROI values when tensor ROI is Empty pass Constant node in Resize Operator

Description:

  • Fix ROI values when tensor ROI is Empty pass Constant node
  • Create test with Constant and Tensor ROI is Empty

Step to Reproduce:

  • Deploy yolov5n.onnx using TVM. When executing relax.transform.LegalizeOps() is happen error: "IndexError: list index out of range" at roi array, because roi = []
  • Error log:

"File ~/Contributes/tvm/python/tvm/topi/image/resize.py:615, in _resize_2d()
608 in_x = x1 * (image_width - 1) + w_scale * x
609 else:
610 in_x = get_inx(
611 x,
612 image_width,
613 target_width,
614 coordinate_transformation_mode,
--> 615 roi[1],
616 roi[3],
617 width_use_int_div,
618 )
619 in_y = get_inx(
620 y,
621 image_height,
(...) 626 height_use_int_div,
627 )
629 if method == "nearest_neighbor":
IndexError: list index out of range"

  • Graph:
PR

Resolve:

  • On the Frontend, when encountering a case where ROI is constant and ROI is empty, the handling is the same as when ROI = None (fill in the ROI tensor with 0.0).

…ode Constant

- Fill value 0.0 into tensor ROI
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @locnd182644, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the ONNX frontend's handling of the Resize operator, specifically when the ROI input tensor is empty. The fix ensures that an empty ROI is properly initialized with zeros, preventing an IndexError and improving the robustness of ONNX model compilation. Comprehensive test cases have been added to validate this new behavior, ensuring that models with empty ROI tensors can be processed correctly.

Highlights

  • ONNX Resize ROI Handling: Implemented a fix in the ONNX frontend to correctly handle cases where the ROI (Region of Interest) tensor for the Resize operator is empty. Previously, this led to an IndexError during processing when deploying models like yolov5n.onnx.
  • Empty ROI Initialization: When an empty ROI tensor is encountered, it is now initialized with a list of zeros, mirroring the behavior when ROI is None, thus preventing runtime errors.
  • Enhanced Test Coverage: New test cases have been added to specifically validate the Resize operator's behavior when the ROI input is an empty list, covering scenarios where ROI is provided as a constant node or as an initializer tensor.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request correctly fixes an IndexError in the ONNX Resize operator frontend when an empty constant tensor is passed for the roi input. The fix handles this edge case by treating it similarly to a None roi, which is appropriate. The added test cases effectively cover this scenario, including variations where roi is provided as a Constant node or an initializer. I've also noted a minor typo fix in an assertion message, which is a good catch.

I have one suggestion to improve the new test cases by ensuring unique test IDs to avoid potential issues with test runners.

Comment on lines +2682 to +2683
roi_list.append(pytest.param(True, roi, True, id=f"roi_{'_'.join(str(x) for x in roi)}"))
roi_list.append(pytest.param(True, roi, False, id=f"roi_{'_'.join(str(x) for x in roi)}"))

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.

medium

The pytest.param calls inside this loop generate duplicate test IDs. For example, when roi is [], both calls will have id="roi_". This can cause issues with test discovery and reporting. To ensure unique test IDs, you should include information about whether roi is a constant or an initializer in the ID string.

Suggested change
roi_list.append(pytest.param(True, roi, True, id=f"roi_{'_'.join(str(x) for x in roi)}"))
roi_list.append(pytest.param(True, roi, False, id=f"roi_{'_'.join(str(x) for x in roi)}"))
roi_list.append(pytest.param(True, roi, True, id=f"const_roi_{'_'.join(str(x) for x in roi)}"))
roi_list.append(pytest.param(True, roi, False, id=f"initializer_roi_{'_'.join(str(x) for x in roi)}"))

@tlopex tlopex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@tlopex tlopex merged commit 6be0db4 into apache:main Jan 30, 2026
10 checks passed
@locnd182644 locnd182644 deleted the Onnx/Resize branch January 30, 2026 14:57
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.

2 participants