|
|
@ -51,10 +51,15 @@ |
|
|
|
#include <opencv2/dnn/shape_utils.hpp> |
|
|
|
#include <opencv2/dnn/shape_utils.hpp> |
|
|
|
#include <opencv2/imgproc.hpp> |
|
|
|
#include <opencv2/imgproc.hpp> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <opencv2/core/utils/configuration.private.hpp> |
|
|
|
|
|
|
|
|
|
|
|
namespace cv { |
|
|
|
namespace cv { |
|
|
|
namespace dnn { |
|
|
|
namespace dnn { |
|
|
|
CV__DNN_EXPERIMENTAL_NS_BEGIN |
|
|
|
CV__DNN_EXPERIMENTAL_NS_BEGIN |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this option is usefull to run valgrind memory errors detection
|
|
|
|
|
|
|
|
static bool DNN_DISABLE_MEMORY_OPTIMIZATIONS = utils::getConfigurationParameterBool("OPENCV_DNN_DISABLE_MEMORY_OPTIMIZATIONS", false); |
|
|
|
|
|
|
|
|
|
|
|
using std::vector; |
|
|
|
using std::vector; |
|
|
|
using std::map; |
|
|
|
using std::map; |
|
|
|
using std::make_pair; |
|
|
|
using std::make_pair; |
|
|
@ -369,7 +374,8 @@ public: |
|
|
|
|
|
|
|
|
|
|
|
void reuseOrCreate(const MatShape& shape, const LayerPin& lp, Mat& dst) |
|
|
|
void reuseOrCreate(const MatShape& shape, const LayerPin& lp, Mat& dst) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef REUSE_DNN_MEMORY |
|
|
|
if (!DNN_DISABLE_MEMORY_OPTIMIZATIONS) |
|
|
|
|
|
|
|
{ |
|
|
|
Mat bestBlob; |
|
|
|
Mat bestBlob; |
|
|
|
LayerPin bestBlobPin; |
|
|
|
LayerPin bestBlobPin; |
|
|
|
|
|
|
|
|
|
|
@ -400,9 +406,10 @@ public: |
|
|
|
{ |
|
|
|
{ |
|
|
|
reuse(bestBlobPin, lp); |
|
|
|
reuse(bestBlobPin, lp); |
|
|
|
dst = bestBlob.reshape(1, 1).colRange(0, targetTotal).reshape(1, shape); |
|
|
|
dst = bestBlob.reshape(1, 1).colRange(0, targetTotal).reshape(1, shape); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
} |
|
|
|
#endif // REUSE_DNN_MEMORY
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// if dst already has been allocated with total(shape) elements,
|
|
|
|
// if dst already has been allocated with total(shape) elements,
|
|
|
|
// it won't be recrreated and pointer of dst.data remains the same.
|
|
|
|
// it won't be recrreated and pointer of dst.data remains the same.
|
|
|
@ -413,7 +420,8 @@ public: |
|
|
|
|
|
|
|
|
|
|
|
void reuseOrCreate(const MatShape& shape, const LayerPin& lp, UMat &umat_dst) |
|
|
|
void reuseOrCreate(const MatShape& shape, const LayerPin& lp, UMat &umat_dst) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifdef REUSE_DNN_MEMORY |
|
|
|
if (!DNN_DISABLE_MEMORY_OPTIMIZATIONS) |
|
|
|
|
|
|
|
{ |
|
|
|
UMat bestBlob; |
|
|
|
UMat bestBlob; |
|
|
|
LayerPin bestBlobPin; |
|
|
|
LayerPin bestBlobPin; |
|
|
|
|
|
|
|
|
|
|
@ -444,9 +452,10 @@ public: |
|
|
|
{ |
|
|
|
{ |
|
|
|
reuse(bestBlobPin, lp); |
|
|
|
reuse(bestBlobPin, lp); |
|
|
|
umat_dst.create(shape, CV_32F); |
|
|
|
umat_dst.create(shape, CV_32F); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
} |
|
|
|
#endif // REUSE_DNN_MEMORY
|
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// if dst already has been allocated with total(shape) elements,
|
|
|
|
// if dst already has been allocated with total(shape) elements,
|
|
|
|
// it won't be recrreated and pointer of dst.data remains the same.
|
|
|
|
// it won't be recrreated and pointer of dst.data remains the same.
|
|
|
|