From f0323fdd1e9a87bcf539e9e4ff2f572195ec642d Mon Sep 17 00:00:00 2001 From: alexlyulkov Date: Tue, 26 Mar 2024 14:00:35 +0300 Subject: [PATCH] Merge pull request #25218 from alexlyulkov:al/int64-tile Allowed int types in Tile and Reduce layers #25218 Allowed any Mat type in Tile layer. Allowed int64 type in Reduce layer. ONNX tests with int32 and int64 inputs will be added later in a separate PR ### 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 - [ ] There is a reference to the original bug report and related work - [ ] 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/layers/reduce_layer.cpp | 11 +++++++++++ modules/dnn/src/layers/tile_layer.cpp | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/modules/dnn/src/layers/reduce_layer.cpp b/modules/dnn/src/layers/reduce_layer.cpp index 30f8139c25..22bf6bd327 100644 --- a/modules/dnn/src/layers/reduce_layer.cpp +++ b/modules/dnn/src/layers/reduce_layer.cpp @@ -131,6 +131,16 @@ public: return false; } + virtual void getTypes(const std::vector& inputs, + const int requiredOutputs, + const int requiredInternals, + std::vector& outputs, + std::vector& internals) const CV_OVERRIDE + { + CV_CheckType(inputs[0], inputs[0] == CV_32F || inputs[0] == CV_32S || inputs[0] == CV_64S || inputs[0] == CV_16F || inputs[0] == CV_8U, ""); + outputs.assign(1, inputs[0]); + } + template class ReduceBase { public: @@ -491,6 +501,7 @@ public: switch (type) { case CV_8U: opDispatch(std::forward(args)...); break; case CV_32S: opDispatch(std::forward(args)...); break; + case CV_64S: opDispatch(std::forward(args)...); break; case CV_32F: opDispatch(std::forward(args)...); break; default: CV_Error(cv::Error::BadDepth, "DNN/Reduce: Unsupported type."); } diff --git a/modules/dnn/src/layers/tile_layer.cpp b/modules/dnn/src/layers/tile_layer.cpp index abaf96bd4a..72a59e62c1 100644 --- a/modules/dnn/src/layers/tile_layer.cpp +++ b/modules/dnn/src/layers/tile_layer.cpp @@ -53,6 +53,15 @@ public: return false; } + void getTypes(const std::vector& inputs, + const int requiredOutputs, + const int requiredInternals, + std::vector& outputs, + std::vector& internals) const CV_OVERRIDE + { + outputs.assign(requiredOutputs, inputs[0]); + } + void forward(InputArrayOfArrays inputs_arr, OutputArrayOfArrays outputs_arr, OutputArrayOfArrays internals_arr) CV_OVERRIDE { CV_TRACE_FUNCTION();