Skip to content

[Relax][ONNX] Support Resize dynamic ROI via TOPI#18963

Merged
tlopex merged 2 commits intoapache:mainfrom
Dayuxiaoshui:main
Apr 2, 2026
Merged

[Relax][ONNX] Support Resize dynamic ROI via TOPI#18963
tlopex merged 2 commits intoapache:mainfrom
Dayuxiaoshui:main

Conversation

@Dayuxiaoshui
Copy link
Copy Markdown
Contributor

The ONNX Resize converter previously rejected non-constant ROI inputs, which blocked models where ROI is provided at runtime. This change adds a dynamic-ROI path lowered through TOPI resize kernels while preserving the existing relax.image.resize* path for static ROI.

Specifically:

  • add reusable helper to convert ONNX full ROI ([starts..., ends...]) into spatial ROI vector
  • add reusable helper to emit topi.image.resize1d/2d/3d for dynamic ROI
  • keep static ROI fast path for relax.image.resize2d/resize3d
  • normalize dynamic ROI expr before emit_te to ensure struct_info is populated
  • handle optional Resize inputs (roi/scales/sizes) more defensively
  • add frontend test coverage with graph-input ROI: test_resize_dynamic_roi_tf_crop_and_resize

Ref: #18945

The ONNX Resize converter previously rejected non-constant ROI inputs, which blocked models where ROI is provided at runtime. This change adds a dynamic-ROI path lowered through TOPI resize kernels while preserving the existing relax.image.resize* path for static ROI.

Specifically:
- add reusable helper to convert ONNX full ROI ([starts..., ends...]) into spatial ROI vector
- add reusable helper to emit topi.image.resize1d/2d/3d for dynamic ROI
- keep static ROI fast path for relax.image.resize2d/resize3d
- normalize dynamic ROI expr before emit_te to ensure struct_info is populated
- handle optional Resize inputs (roi/scales/sizes) more defensively
- add frontend test coverage with graph-input ROI:
  test_resize_dynamic_roi_tf_crop_and_resize

Ref: apache#18945
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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 introduces support for dynamic Region of Interest (ROI) in the ONNX Resize operator by leveraging TOPI's dynamic-ROI path. It adds helper functions to map ONNX ROI to spatial ROI and emit TOPI resize operations for 1D, 2D, and 3D data. The review feedback identifies a bug in the ROI index mapping for 3D resizing, where the order must be adjusted to match TOPI's expectations, and points out an invalid assertion that always evaluates to true and should be replaced with a proper exception.

Comment thread python/tvm/relax/frontend/onnx/onnx_frontend.py Outdated
Comment thread python/tvm/relax/frontend/onnx/onnx_frontend.py Outdated
Copy link
Copy Markdown
Member

@tlopex tlopex left a comment

Choose a reason for hiding this comment

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

The current test only covers the 2D case. Please add at least a 3D dynamic ROI test as well

Comment thread python/tvm/relax/frontend/onnx/onnx_frontend.py Outdated
Comment thread python/tvm/relax/frontend/onnx/onnx_frontend.py Outdated
@Dayuxiaoshui
Copy link
Copy Markdown
Contributor Author

cc @tlopex

- Reorder ONNX NCDHW spatial ROI (D,H,W) to TOPI resize3d (W,H,D) for
  emit_te dynamic path; apply the same mapping for static 5D ROI to
  relax.image.resize3d.
- Replace invalid assert f-string branches with ValueError for
  unsupported scales/sizes types.
- Add test_resize_dynamic_roi_3d_tf_crop_and_resize with explicit
  full-tensor ROI inputs for stable ORT vs TVM comparison.

Ref: apache#18945
Copy link
Copy Markdown
Member

@tlopex tlopex left a comment

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 ec0daad into apache:main Apr 2, 2026
9 checks passed
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