From: Alexander Alekhin Date: Wed, 22 Nov 2017 11:00:58 +0000 (+0300) Subject: dnn: sync output/internals blobs back X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~387^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9db5cbf9a4763b702d9c566d939648ca3447c1eb;p=platform%2Fupstream%2Fopencv.git dnn: sync output/internals blobs back --- diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index 9fdc5a9..65408d5 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -357,6 +357,9 @@ public: void assign(const UMat& u) const; void assign(const Mat& m) const; + + void assign(const std::vector& v) const; + void assign(const std::vector& v) const; }; diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 0208a71..a85effc 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -3053,6 +3053,82 @@ void _OutputArray::assign(const Mat& m) const } +void _OutputArray::assign(const std::vector& v) const +{ + int k = kind(); + if (k == STD_VECTOR_UMAT) + { + std::vector& this_v = *(std::vector*)obj; + CV_Assert(this_v.size() == v.size()); + + for (size_t i = 0; i < v.size(); i++) + { + const UMat& m = v[i]; + UMat& this_m = this_v[i]; + if (this_m.u != NULL && this_m.u == m.u) + continue; // same object (see dnn::Layer::forward_fallback) + m.copyTo(this_m); + } + } + else if (k == STD_VECTOR_MAT) + { + std::vector& this_v = *(std::vector*)obj; + CV_Assert(this_v.size() == v.size()); + + for (size_t i = 0; i < v.size(); i++) + { + const UMat& m = v[i]; + Mat& this_m = this_v[i]; + if (this_m.u != NULL && this_m.u == m.u) + continue; // same object (see dnn::Layer::forward_fallback) + m.copyTo(this_m); + } + } + else + { + CV_Error(Error::StsNotImplemented, ""); + } +} + + +void _OutputArray::assign(const std::vector& v) const +{ + int k = kind(); + if (k == STD_VECTOR_UMAT) + { + std::vector& this_v = *(std::vector*)obj; + CV_Assert(this_v.size() == v.size()); + + for (size_t i = 0; i < v.size(); i++) + { + const Mat& m = v[i]; + UMat& this_m = this_v[i]; + if (this_m.u != NULL && this_m.u == m.u) + continue; // same object (see dnn::Layer::forward_fallback) + m.copyTo(this_m); + } + } + else if (k == STD_VECTOR_MAT) + { + std::vector& this_v = *(std::vector*)obj; + CV_Assert(this_v.size() == v.size()); + + for (size_t i = 0; i < v.size(); i++) + { + const Mat& m = v[i]; + Mat& this_m = this_v[i]; + if (this_m.u != NULL && this_m.u == m.u) + continue; // same object (see dnn::Layer::forward_fallback) + m.copyTo(this_m); + } + } + else + { + CV_Error(Error::StsNotImplemented, ""); + } +} + + static _InputOutputArray _none; InputOutputArray noArray() { return _none; } diff --git a/modules/dnn/src/dnn.cpp b/modules/dnn/src/dnn.cpp index 40edf7a..4faffe1 100644 --- a/modules/dnn/src/dnn.cpp +++ b/modules/dnn/src/dnn.cpp @@ -2381,6 +2381,10 @@ void Layer::forward_fallback(InputArrayOfArrays inputs_arr, OutputArrayOfArrays inputs[i] = &inpvec[i]; this->forward(inputs, outputs, internals); + + // sync results back + outputs_arr.assign(outputs); + internals_arr.assign(internals); } void Layer::run(const std::vector &inputs, std::vector &outputs, std::vector &internals)