dnn onnx graph simplifier: handle optional inputs of Slice#24655
dnn onnx graph simplifier: handle optional inputs of Slice#24655asmorkalov merged 2 commits intoopencv:4.xfrom
Conversation
|
@dkurt What do you think about this solution? |
|
|
||
| int shape2 = addNodeToMatch("Shape", input); | ||
| int slice = addNodeToMatch("Slice", shape2, addNodeToMatch("Constant"), addNodeToMatch("Constant"), addNodeToMatch("Constant")); | ||
| int slice = addNodeToMatch("Slice", shape2, addNodeToMatch("Constant"), addNodeToMatch("Constant")); |
There was a problem hiding this comment.
Should ResizeSubgraph1 be modified in the same way?
There was a problem hiding this comment.
No. This subgraph is added to simplify model resize_nearest_unfused_opset11_torch1.4.onnx in opencv_extra. This graph does not have shape pre-inferred, so there is no value info proto for the input of the Slice operator. The actual axes value is 0, which is not -1 and cannot be recognized as the last axis because there is no shape inference information.
There was a problem hiding this comment.
Got it. So as I tried propose here can we align all the Slice layers matches to accept 5 mandatory inputs but add a pattern which appends optional inputs if missed?
There was a problem hiding this comment.
However, current proposal also looks good to me and it make sense to merge to unblock Attention layer.
There was a problem hiding this comment.
5 inputs
I would say it can be more robust as it also handles cases where value info proto is not available. However, it needs to create ONNX Constant nodes for axes and steps in finalize() which I am not sure how to do.
| } | ||
|
|
||
| /* Slice operator has two optional inputs "axes" and "steps". Some models may be set to have | ||
| Slice with optional inputs of default values, some of them don't. This Subgraph removes |
There was a problem hiding this comment.
some of them don't
Means two things - they still have such inputs but with different values or they don't have inputs at all.
Can we do matching-fusion in the opposite way - align all the Slice layers (with less than 5 inputs) to some canonical version with 5 inputs? Filling missed values with default ones.
…ional_input dnn onnx graph simplifier: handle optional inputs of Slice opencv#24655 Resolves opencv#24609 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
Resolves #24609
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.