[mir] Add Resize v10 and v11 operator to ONNX importer#16418
[mir] Add Resize v10 and v11 operator to ONNX importer#16418arkq wants to merge 2 commits intoSamsung:masterfrom
Conversation
There was a problem hiding this comment.
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.himplementing theconvertResizeV10converter function - Registration of
Resizeat opset 10 (supported) and opsets 11+ (unsupported) inONNXOpRegistration.h CMakeLists.txtupdated 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.
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>
There was a problem hiding this comment.
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.
| 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(); |
There was a problem hiding this comment.
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:
- The size check
inputs.size() < 3on 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. - When ROI is empty but both scales and sizes are present, the
inputsvector becomes[X, scales, sizes], soinputs[2]will besizes, notscales— 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.
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>
|
@arkq May I ask why did you add a new opto |
And |
Hmm... I thought that the code for |
|
Closing this PR because the |
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
UpsampleV9but sinceUpsampleis deprecated since v10, later, we can add more recent versions ofResizeoperator.ONE-DCO-1.0-Signed-off-by: Arkadiusz Bokowy a.bokowy@samsung.com