Skip to content

Commit

Permalink
Merge pull request #3794 from vpisarev:new_dnn_engine
Browse files Browse the repository at this point in the history
New dnn engine #3794

This is a companion for opencv/opencv#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
  • Loading branch information
vpisarev authored Oct 16, 2024
1 parent d131137 commit 31be64e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
38 changes: 19 additions & 19 deletions modules/dnn_superres/src/dnn_superres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class DepthToSpace CV_FINAL : public cv::dnn::Layer

static cv::Ptr<cv::dnn::Layer> create(cv::dnn::LayerParams& params);

virtual bool getMemoryShapes(const std::vector<std::vector<int> > &inputs,
virtual bool getMemoryShapes(const std::vector<MatShape> &inputs_,
const int,
std::vector<std::vector<int> > &outputs,
std::vector<std::vector<int> > &) const CV_OVERRIDE;
std::vector<MatShape> &outputs_,
std::vector<MatShape> &) const CV_OVERRIDE;

virtual void forward(cv::InputArrayOfArrays inputs_arr,
cv::OutputArrayOfArrays outputs_arr,
Expand Down Expand Up @@ -308,39 +308,39 @@ cv::Ptr<cv::dnn::Layer> DepthToSpace::create(cv::dnn::LayerParams &params)
return cv::Ptr<cv::dnn::Layer>(new DepthToSpace(params));
}

bool DepthToSpace::getMemoryShapes(const std::vector <std::vector<int>> &inputs,
const int, std::vector <std::vector<int>> &outputs, std::vector <std::vector<int>> &) const
bool DepthToSpace::getMemoryShapes(const std::vector <MatShape> &inpShapes,
const int, std::vector <MatShape> &outShapes, std::vector <MatShape> &) const
{
std::vector<int> 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<int>(sqrt(inputs[0][1]));
scale = static_cast<int>(sqrt(inpShapes[0][1]));
}
else // Three image channels
{
scale = static_cast<int>(sqrt(inputs[0][1]/3));
scale = static_cast<int>(sqrt(inpShapes[0][1]/3));
}

outShape[0] = inputs[0][0];
outShape[1] = static_cast<int>(inputs[0][1] / pow(scale,2));
outShape[2] = static_cast<int>(scale * inputs[0][2]);
outShape[3] = static_cast<int>(scale * inputs[0][3]);
outShape[0] = inpShapes[0][0];
outShape[1] = static_cast<int>(inpShapes[0][1] / pow(scale,2));
outShape[2] = static_cast<int>(scale * inpShapes[0][2]);
outShape[3] = static_cast<int>(scale * inpShapes[0][3]);

outputs.assign(4, outShape);
outShapes.assign(1, outShape);

return false;
}

void DepthToSpace::forward(cv::InputArrayOfArrays inputs_arr, cv::OutputArrayOfArrays outputs_arr,
cv::OutputArrayOfArrays)
{
std::vector <cv::Mat> inputs, outputs;
inputs_arr.getMatVector(inputs);
outputs_arr.getMatVector(outputs);
cv::Mat &inp = inputs[0];
cv::Mat &out = outputs[0];
std::vector <cv::Mat> 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;

Expand Down
4 changes: 2 additions & 2 deletions modules/text/src/ocr_holistic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<dnn::MatShape> inShapes, outShapes;
vector<MatShape> 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);
Expand Down

0 comments on commit 31be64e

Please sign in to comment.