From d7f04a9d33d9c7d7c4d829fe6a5e55955d158e3a Mon Sep 17 00:00:00 2001 From: Abduragim Shtanchaev <44877829+Abdurrahheem@users.noreply.github.com> Date: Fri, 31 May 2024 14:13:36 +0400 Subject: [PATCH] Merge pull request #25660 from Abdurrahheem:ash/fix-slice-empty-input Slice layer parser fix to support empty input case #25660 This PR fixes Slice Layer's parser to handle empty input cases (cases with initializer) It fixed the issue rased in #24838 ### 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 --- modules/dnn/src/onnx/onnx_importer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index b09a9ed360..7b63e39a3a 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -1202,7 +1202,12 @@ void ONNXImporter::parseReduce(LayerParams& layerParams, const opencv_onnx::Node void ONNXImporter::parseSlice(LayerParams& layerParams, const opencv_onnx::NodeProto& node_proto) { - MatShape inpShape = outShapes[node_proto.input(0)]; + MatShape inpShape; + if (constBlobs.find(node_proto.input(0)) != constBlobs.end()) + inpShape = shape(getBlob(node_proto, 0)); + else { + inpShape = outShapes[node_proto.input(0)]; + } int dims = inpShape.size(); std::vector begin(dims, 0); std::vector end(dims, INT_MAX);