Skip to content

[mir] Add Resize v10 and v11 operator to ONNX importer#16418

Closed
arkq wants to merge 2 commits intoSamsung:masterfrom
arkq:mir-resize
Closed

[mir] Add Resize v10 and v11 operator to ONNX importer#16418
arkq wants to merge 2 commits intoSamsung:masterfrom
arkq:mir-resize

Conversation

@arkq
Copy link
Copy Markdown
Contributor

@arkq arkq commented Mar 4, 2026

This PR adds Resize operator in versions 10 and 11 to ONNX importer. Such operator can be used in YuNet models and is required to convert YuNet ONNX model to circle format.

Specification:
https://onnx.ai/onnx/operators/onnx__Resize.html

For now this operator behaves mostly like UpsampleV9 but since Upsample is deprecated since v10, later, we can add more recent versions of Resize operator.

ONE-DCO-1.0-Signed-off-by: Arkadiusz Bokowy a.bokowy@samsung.com

Copilot AI review requested due to automatic review settings March 4, 2026 12:01
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for the ONNX Resize operator at opset version 10 to the MIR ONNX importer, enabling conversion of YuNet ONNX models (which use this operator) to the circle format. The implementation closely follows the existing Upsample v9 converter pattern and relies on the existing mir::ops::ResizeOp backend.

Changes:

  • New Resize.cpp / Resize.h implementing the convertResizeV10 converter function
  • Registration of Resize at opset 10 (supported) and opsets 11+ (unsupported) in ONNXOpRegistration.h
  • CMakeLists.txt updated to include the two new source files

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
compiler/mir/src/mir_onnx_importer/Op/Resize.cpp Core implementation of the Resize v10 converter
compiler/mir/src/mir_onnx_importer/Op/Resize.h Header declaring the convertResizeV10 function
compiler/mir/src/mir_onnx_importer/ONNXOpRegistration.h Registers Resize v10 as supported and v11+ as unsupported
compiler/mir/src/mir_onnx_importer/CMakeLists.txt Adds the new source files to the build

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread compiler/mir/src/mir_onnx_importer/Op/Resize.cpp
Comment thread compiler/mir/src/mir_onnx_importer/Op/Resize.cpp Outdated
Comment thread compiler/mir/src/mir_onnx_importer/Op/Resize.cpp Outdated
This commit adds Resize operator in version 10 to ONNX importer. Such
operator can be used in YuNet models and is required to convert YuNet
ONNX model to circle format.

ONE-DCO-1.0-Signed-off-by: Arkadiusz Bokowy <a.bokowy@samsung.com>
@arkq arkq changed the title [mir] Add Resize v10 operator to ONNX importer [mir] Add Resize v10 and v11 operator to ONNX importer Mar 5, 2026
@arkq arkq requested a review from Copilot March 5, 2026 15:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +100 to +110
if (inputs.size() < 3 || inputs.size() > 4)
throw std::runtime_error{"Resize v11: Expected between 3 and 4 inputs"};

int rank = inputs[0]->getShape().rank();
if (rank != 4)
throw std::runtime_error("Resize v11: Only 4-D input is supported");

auto *scales = dynamic_cast<mir::ops::ConstantOp *>(inputs[2]->getNode());
assert(scales && "Scales could be a constant tensor only");
auto scales_tensor = mir::Tensor<float>(scales->getValue());
auto scales_tensor_elements = scales_tensor.getShape().numElements();
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

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

getNodeInputs (in ONNXNodeConverterRegistry.cpp) skips empty input names and returns a compacted vector. For Resize v11, the ROI input (ONNX positional index 1) is required only for tf_crop_and_resize mode. Since this implementation only supports half_pixel mode, the ROI input will commonly have an empty name in the ONNX node. When that happens, the returned inputs vector will be [X, scales] (size 2) or [X, scales, sizes] (size 3) instead of [X, ROI, scales, sizes].

Concretely, two issues arise:

  1. The size check inputs.size() < 3 on line 100 will incorrectly reject valid Resize v11 nodes that have an empty ROI and provide only scales (a common case), even though such nodes are entirely valid.
  2. When ROI is empty but both scales and sizes are present, the inputs vector becomes [X, scales, sizes], so inputs[2] will be sizes, not scales — reversing the roles of scales and sizes.

The input indexing logic should account for the possibility of the ROI input being absent from the compacted vector, for instance by reading the ONNX node input names directly to handle optional/empty inputs before indexing into inputs.

Copilot uses AI. Check for mistakes.
Comment thread compiler/mir/src/mir_onnx_importer/Op/Resize.cpp Outdated
Comment thread compiler/mir/src/mir_onnx_importer/Op/Resize.cpp Outdated
This commit adds support for importing a subset of Resize v11 operator.
As of now only nearest interpolation mode is supported with half down
rounding method.

ONE-DCO-1.0-Signed-off-by: Arkadiusz Bokowy <a.bokowy@samsung.com>
@batcheu
Copy link
Copy Markdown
Contributor

batcheu commented Mar 10, 2026

@arkq May I ask why did you add a new opto mir-onnx-importer?
AFAIK, the library is only used by onnx2tflite which is replaced by onnx2circle.

@hseok-oh
Copy link
Copy Markdown
Contributor

@arkq May I ask why did you add a new opto mir-onnx-importer? AFAIK, the library is only used by onnx2tflite which is replaced by onnx2circle.

And compiler/onnx2circle is not used.

@batcheu
Copy link
Copy Markdown
Contributor

batcheu commented Mar 10, 2026

@arkq May I ask why did you add a new opto mir-onnx-importer? AFAIK, the library is only used by onnx2tflite which is replaced by onnx2circle.

@arkq FYI, here onnx2circle is the tool based on circle-mlir. (compiler/onnx2circle is not used as @hseok-oh said)

@arkq
Copy link
Copy Markdown
Contributor Author

arkq commented Mar 10, 2026

May I ask why did you add a new opto mir-onnx-importer?
AFAIK, the library is only used by onnx2tflite which is replaced by onnx2circle.

Hmm... I thought that the code for onnx2circle tool is compiler/onnx2circle... But if onnx2circle is a tool implemented by circle-mlir than I will have to read the code in the repo once more. Anyway, having a tool onnx2circle and a library compiler/onnx2circle which is not used to create such tool is somehow confusing, to put it mildly, for someone not familiar with the code base :D

@arkq
Copy link
Copy Markdown
Contributor Author

arkq commented Mar 12, 2026

Closing this PR because the ‎compiler/onnx2circle module is deprecated.

@arkq arkq closed this Mar 12, 2026
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