Skip to content

Commit 9db5cbf

Browse files
committed
dnn: sync output/internals blobs back
1 parent 0f34628 commit 9db5cbf

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

modules/core/include/opencv2/core/mat.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ class CV_EXPORTS _OutputArray : public _InputArray
357357

358358
void assign(const UMat& u) const;
359359
void assign(const Mat& m) const;
360+
361+
void assign(const std::vector<UMat>& v) const;
362+
void assign(const std::vector<Mat>& v) const;
360363
};
361364

362365

modules/core/src/matrix.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,6 +3053,82 @@ void _OutputArray::assign(const Mat& m) const
30533053
}
30543054

30553055

3056+
void _OutputArray::assign(const std::vector<UMat>& v) const
3057+
{
3058+
int k = kind();
3059+
if (k == STD_VECTOR_UMAT)
3060+
{
3061+
std::vector<UMat>& this_v = *(std::vector<UMat>*)obj;
3062+
CV_Assert(this_v.size() == v.size());
3063+
3064+
for (size_t i = 0; i < v.size(); i++)
3065+
{
3066+
const UMat& m = v[i];
3067+
UMat& this_m = this_v[i];
3068+
if (this_m.u != NULL && this_m.u == m.u)
3069+
continue; // same object (see dnn::Layer::forward_fallback)
3070+
m.copyTo(this_m);
3071+
}
3072+
}
3073+
else if (k == STD_VECTOR_MAT)
3074+
{
3075+
std::vector<Mat>& this_v = *(std::vector<Mat>*)obj;
3076+
CV_Assert(this_v.size() == v.size());
3077+
3078+
for (size_t i = 0; i < v.size(); i++)
3079+
{
3080+
const UMat& m = v[i];
3081+
Mat& this_m = this_v[i];
3082+
if (this_m.u != NULL && this_m.u == m.u)
3083+
continue; // same object (see dnn::Layer::forward_fallback)
3084+
m.copyTo(this_m);
3085+
}
3086+
}
3087+
else
3088+
{
3089+
CV_Error(Error::StsNotImplemented, "");
3090+
}
3091+
}
3092+
3093+
3094+
void _OutputArray::assign(const std::vector<Mat>& v) const
3095+
{
3096+
int k = kind();
3097+
if (k == STD_VECTOR_UMAT)
3098+
{
3099+
std::vector<UMat>& this_v = *(std::vector<UMat>*)obj;
3100+
CV_Assert(this_v.size() == v.size());
3101+
3102+
for (size_t i = 0; i < v.size(); i++)
3103+
{
3104+
const Mat& m = v[i];
3105+
UMat& this_m = this_v[i];
3106+
if (this_m.u != NULL && this_m.u == m.u)
3107+
continue; // same object (see dnn::Layer::forward_fallback)
3108+
m.copyTo(this_m);
3109+
}
3110+
}
3111+
else if (k == STD_VECTOR_MAT)
3112+
{
3113+
std::vector<Mat>& this_v = *(std::vector<Mat>*)obj;
3114+
CV_Assert(this_v.size() == v.size());
3115+
3116+
for (size_t i = 0; i < v.size(); i++)
3117+
{
3118+
const Mat& m = v[i];
3119+
Mat& this_m = this_v[i];
3120+
if (this_m.u != NULL && this_m.u == m.u)
3121+
continue; // same object (see dnn::Layer::forward_fallback)
3122+
m.copyTo(this_m);
3123+
}
3124+
}
3125+
else
3126+
{
3127+
CV_Error(Error::StsNotImplemented, "");
3128+
}
3129+
}
3130+
3131+
30563132
static _InputOutputArray _none;
30573133
InputOutputArray noArray() { return _none; }
30583134

modules/dnn/src/dnn.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,6 +2381,10 @@ void Layer::forward_fallback(InputArrayOfArrays inputs_arr, OutputArrayOfArrays
23812381
inputs[i] = &inpvec[i];
23822382

23832383
this->forward(inputs, outputs, internals);
2384+
2385+
// sync results back
2386+
outputs_arr.assign(outputs);
2387+
internals_arr.assign(internals);
23842388
}
23852389

23862390
void Layer::run(const std::vector<Mat> &inputs, std::vector<Mat> &outputs, std::vector<Mat> &internals)

0 commit comments

Comments
 (0)