From 31be64eae74f785e1a368847d0ca75a4080edbfd Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Wed, 16 Oct 2024 15:29:03 +0300 Subject: [PATCH] Merge pull request #3794 from vpisarev:new_dnn_engine New dnn engine #3794 This is a companion for https://github.com/opencv/opencv/pull/26056 - [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. - [ ] The feature is well documented and sample code can be built with the project CMake --- modules/dnn_superres/src/dnn_superres.cpp | 38 +++++++++++------------ modules/text/src/ocr_holistic.cpp | 4 +-- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/dnn_superres/src/dnn_superres.cpp b/modules/dnn_superres/src/dnn_superres.cpp index 12c93a68d03..8dcc86ac81d 100644 --- a/modules/dnn_superres/src/dnn_superres.cpp +++ b/modules/dnn_superres/src/dnn_superres.cpp @@ -20,10 +20,10 @@ class DepthToSpace CV_FINAL : public cv::dnn::Layer static cv::Ptr create(cv::dnn::LayerParams& params); - virtual bool getMemoryShapes(const std::vector > &inputs, + virtual bool getMemoryShapes(const std::vector &inputs_, const int, - std::vector > &outputs, - std::vector > &) const CV_OVERRIDE; + std::vector &outputs_, + std::vector &) const CV_OVERRIDE; virtual void forward(cv::InputArrayOfArrays inputs_arr, cv::OutputArrayOfArrays outputs_arr, @@ -308,27 +308,27 @@ cv::Ptr DepthToSpace::create(cv::dnn::LayerParams ¶ms) return cv::Ptr(new DepthToSpace(params)); } -bool DepthToSpace::getMemoryShapes(const std::vector > &inputs, - const int, std::vector > &outputs, std::vector > &) const +bool DepthToSpace::getMemoryShapes(const std::vector &inpShapes, + const int, std::vector &outShapes, std::vector &) const { - std::vector outShape(4); + MatShape outShape(4); int scale; - if( inputs[0][1] == 4 || inputs[0][1] == 9 || inputs[0][1] == 16 ) //Only one image channel + if( inpShapes[0][1] == 4 || inpShapes[0][1] == 9 || inpShapes[0][1] == 16 ) //Only one image channel { - scale = static_cast(sqrt(inputs[0][1])); + scale = static_cast(sqrt(inpShapes[0][1])); } else // Three image channels { - scale = static_cast(sqrt(inputs[0][1]/3)); + scale = static_cast(sqrt(inpShapes[0][1]/3)); } - outShape[0] = inputs[0][0]; - outShape[1] = static_cast(inputs[0][1] / pow(scale,2)); - outShape[2] = static_cast(scale * inputs[0][2]); - outShape[3] = static_cast(scale * inputs[0][3]); + outShape[0] = inpShapes[0][0]; + outShape[1] = static_cast(inpShapes[0][1] / pow(scale,2)); + outShape[2] = static_cast(scale * inpShapes[0][2]); + outShape[3] = static_cast(scale * inpShapes[0][3]); - outputs.assign(4, outShape); + outShapes.assign(1, outShape); return false; } @@ -336,11 +336,11 @@ bool DepthToSpace::getMemoryShapes(const std::vector > &inputs, void DepthToSpace::forward(cv::InputArrayOfArrays inputs_arr, cv::OutputArrayOfArrays outputs_arr, cv::OutputArrayOfArrays) { - std::vector inputs, outputs; - inputs_arr.getMatVector(inputs); - outputs_arr.getMatVector(outputs); - cv::Mat &inp = inputs[0]; - cv::Mat &out = outputs[0]; + std::vector inputs_, outputs_; + inputs_arr.getMatVector(inputs_); + outputs_arr.getMatVector(outputs_); + cv::Mat &inp = inputs_[0]; + cv::Mat &out = outputs_[0]; const float *inpData = (float *) inp.data; float *outData = (float *) out.data; diff --git a/modules/text/src/ocr_holistic.cpp b/modules/text/src/ocr_holistic.cpp index cb2a20c1b15..870f72a0fdf 100644 --- a/modules/text/src/ocr_holistic.cpp +++ b/modules/text/src/ocr_holistic.cpp @@ -69,12 +69,12 @@ class OCRHolisticWordRecognizerImpl CV_FINAL : public OCRHolisticWordRecognizer size_t getClassCount() { int id = net.getLayerId("prob"); - dnn::MatShape inputShape; + MatShape inputShape; inputShape.push_back(1); inputShape.push_back(1); inputShape.push_back(getPerceptiveField().height); inputShape.push_back(getPerceptiveField().width); - vector inShapes, outShapes; + vector inShapes, outShapes; net.getLayerShapes(inputShape, CV_32F, id, inShapes, outShapes); CV_Assert(outShapes.size() == 1 && outShapes[0].size() == 4); CV_Assert(outShapes[0][0] == 1 && outShapes[0][2] == 1 && outShapes[0][3] == 1);