mirror of
https://github.com/opencv/opencv.git
synced 2025-06-13 21:23:31 +08:00
Merge pull request #16580 from dkurt:fix_14566
This commit is contained in:
commit
a8c257cecb
@ -112,13 +112,18 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ElementWiseLayer(const Func &f=Func()) : run_parallel(false) { func = f; }
|
ElementWiseLayer(const Func &f=Func()) { func = f; }
|
||||||
|
|
||||||
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
virtual bool supportBackend(int backendId) CV_OVERRIDE
|
||||||
{
|
{
|
||||||
return func.supportBackend(backendId, this->preferableTarget);
|
return func.supportBackend(backendId, this->preferableTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void finalize(InputArrayOfArrays, OutputArrayOfArrays) CV_OVERRIDE
|
||||||
|
{
|
||||||
|
func.finalize();
|
||||||
|
}
|
||||||
|
|
||||||
virtual Ptr<BackendNode> tryAttach(const Ptr<BackendNode>& node) CV_OVERRIDE
|
virtual Ptr<BackendNode> tryAttach(const Ptr<BackendNode>& node) CV_OVERRIDE
|
||||||
{
|
{
|
||||||
switch (node->backendId)
|
switch (node->backendId)
|
||||||
@ -235,7 +240,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
Func func;
|
Func func;
|
||||||
bool run_parallel;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef HAVE_OPENCL
|
#ifdef HAVE_OPENCL
|
||||||
@ -250,7 +254,16 @@ static String oclGetTMacro(const UMat &m)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct ReLUFunctor
|
struct BaseFunctor
|
||||||
|
{
|
||||||
|
void finalize() {}
|
||||||
|
|
||||||
|
bool tryFuse(Ptr<dnn::Layer>&) { return false; }
|
||||||
|
|
||||||
|
void getScaleShift(Mat&, Mat&) const {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ReLUFunctor : public BaseFunctor
|
||||||
{
|
{
|
||||||
typedef ReLULayer Layer;
|
typedef ReLULayer Layer;
|
||||||
float slope;
|
float slope;
|
||||||
@ -376,14 +389,10 @@ struct ReLUFunctor
|
|||||||
}
|
}
|
||||||
#endif // HAVE_DNN_NGRAPH
|
#endif // HAVE_DNN_NGRAPH
|
||||||
|
|
||||||
bool tryFuse(Ptr<dnn::Layer>&) { return false; }
|
|
||||||
|
|
||||||
void getScaleShift(Mat&, Mat&) const {}
|
|
||||||
|
|
||||||
int64 getFLOPSPerElement() const { return 1; }
|
int64 getFLOPSPerElement() const { return 1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ReLU6Functor
|
struct ReLU6Functor : public BaseFunctor
|
||||||
{
|
{
|
||||||
typedef ReLU6Layer Layer;
|
typedef ReLU6Layer Layer;
|
||||||
float minValue, maxValue;
|
float minValue, maxValue;
|
||||||
@ -486,14 +495,10 @@ struct ReLU6Functor
|
|||||||
}
|
}
|
||||||
#endif // HAVE_DNN_NGRAPH
|
#endif // HAVE_DNN_NGRAPH
|
||||||
|
|
||||||
bool tryFuse(Ptr<dnn::Layer>&) { return false; }
|
|
||||||
|
|
||||||
void getScaleShift(Mat&, Mat&) const {}
|
|
||||||
|
|
||||||
int64 getFLOPSPerElement() const { return 2; }
|
int64 getFLOPSPerElement() const { return 2; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TanHFunctor
|
struct TanHFunctor : public BaseFunctor
|
||||||
{
|
{
|
||||||
typedef TanHLayer Layer;
|
typedef TanHLayer Layer;
|
||||||
|
|
||||||
@ -565,14 +570,10 @@ struct TanHFunctor
|
|||||||
}
|
}
|
||||||
#endif // HAVE_DNN_NGRAPH
|
#endif // HAVE_DNN_NGRAPH
|
||||||
|
|
||||||
bool tryFuse(Ptr<dnn::Layer>&) { return false; }
|
|
||||||
|
|
||||||
void getScaleShift(Mat&, Mat&) const {}
|
|
||||||
|
|
||||||
int64 getFLOPSPerElement() const { return 1; }
|
int64 getFLOPSPerElement() const { return 1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SwishFunctor
|
struct SwishFunctor : public BaseFunctor
|
||||||
{
|
{
|
||||||
typedef SwishLayer Layer;
|
typedef SwishLayer Layer;
|
||||||
|
|
||||||
@ -645,15 +646,10 @@ struct SwishFunctor
|
|||||||
}
|
}
|
||||||
#endif // HAVE_DNN_NGRAPH
|
#endif // HAVE_DNN_NGRAPH
|
||||||
|
|
||||||
bool tryFuse(Ptr<dnn::Layer>&) { return false; }
|
|
||||||
|
|
||||||
void getScaleShift(Mat&, Mat&) const {}
|
|
||||||
|
|
||||||
int64 getFLOPSPerElement() const { return 3; }
|
int64 getFLOPSPerElement() const { return 3; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MishFunctor
|
struct MishFunctor : public BaseFunctor
|
||||||
{
|
{
|
||||||
typedef MishLayer Layer;
|
typedef MishLayer Layer;
|
||||||
|
|
||||||
@ -731,15 +727,10 @@ struct MishFunctor
|
|||||||
}
|
}
|
||||||
#endif // HAVE_DNN_NGRAPH
|
#endif // HAVE_DNN_NGRAPH
|
||||||
|
|
||||||
bool tryFuse(Ptr<dnn::Layer>&) { return false; }
|
|
||||||
|
|
||||||
void getScaleShift(Mat&, Mat&) const {}
|
|
||||||
|
|
||||||
int64 getFLOPSPerElement() const { return 3; }
|
int64 getFLOPSPerElement() const { return 3; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SigmoidFunctor
|
struct SigmoidFunctor : public BaseFunctor
|
||||||
{
|
{
|
||||||
typedef SigmoidLayer Layer;
|
typedef SigmoidLayer Layer;
|
||||||
|
|
||||||
@ -811,19 +802,13 @@ struct SigmoidFunctor
|
|||||||
}
|
}
|
||||||
#endif // HAVE_DNN_NGRAPH
|
#endif // HAVE_DNN_NGRAPH
|
||||||
|
|
||||||
bool tryFuse(Ptr<dnn::Layer>&) { return false; }
|
|
||||||
|
|
||||||
void getScaleShift(Mat&, Mat&) const {}
|
|
||||||
|
|
||||||
int64 getFLOPSPerElement() const { return 3; }
|
int64 getFLOPSPerElement() const { return 3; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ELUFunctor
|
struct ELUFunctor : public BaseFunctor
|
||||||
{
|
{
|
||||||
typedef ELULayer Layer;
|
typedef ELULayer Layer;
|
||||||
|
|
||||||
explicit ELUFunctor() {}
|
|
||||||
|
|
||||||
bool supportBackend(int backendId, int)
|
bool supportBackend(int backendId, int)
|
||||||
{
|
{
|
||||||
return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_HALIDE ||
|
return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_HALIDE ||
|
||||||
@ -892,14 +877,10 @@ struct ELUFunctor
|
|||||||
}
|
}
|
||||||
#endif // HAVE_DNN_NGRAPH
|
#endif // HAVE_DNN_NGRAPH
|
||||||
|
|
||||||
bool tryFuse(Ptr<dnn::Layer>&) { return false; }
|
|
||||||
|
|
||||||
void getScaleShift(Mat&, Mat&) const {}
|
|
||||||
|
|
||||||
int64 getFLOPSPerElement() const { return 2; }
|
int64 getFLOPSPerElement() const { return 2; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AbsValFunctor
|
struct AbsValFunctor : public BaseFunctor
|
||||||
{
|
{
|
||||||
typedef AbsLayer Layer;
|
typedef AbsLayer Layer;
|
||||||
|
|
||||||
@ -977,14 +958,10 @@ struct AbsValFunctor
|
|||||||
}
|
}
|
||||||
#endif // HAVE_DNN_NGRAPH
|
#endif // HAVE_DNN_NGRAPH
|
||||||
|
|
||||||
bool tryFuse(Ptr<dnn::Layer>&) { return false; }
|
|
||||||
|
|
||||||
void getScaleShift(Mat&, Mat&) const {}
|
|
||||||
|
|
||||||
int64 getFLOPSPerElement() const { return 1; }
|
int64 getFLOPSPerElement() const { return 1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BNLLFunctor
|
struct BNLLFunctor : public BaseFunctor
|
||||||
{
|
{
|
||||||
typedef BNLLLayer Layer;
|
typedef BNLLLayer Layer;
|
||||||
|
|
||||||
@ -1057,23 +1034,19 @@ struct BNLLFunctor
|
|||||||
}
|
}
|
||||||
#endif // HAVE_DNN_NGRAPH
|
#endif // HAVE_DNN_NGRAPH
|
||||||
|
|
||||||
bool tryFuse(Ptr<dnn::Layer>&) { return false; }
|
|
||||||
|
|
||||||
void getScaleShift(Mat&, Mat&) const {}
|
|
||||||
|
|
||||||
int64 getFLOPSPerElement() const { return 5; }
|
int64 getFLOPSPerElement() const { return 5; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PowerFunctor
|
struct PowerFunctor : public BaseFunctor
|
||||||
{
|
{
|
||||||
typedef PowerLayer Layer;
|
typedef PowerLayer Layer;
|
||||||
|
|
||||||
float power;
|
float power, scale, shift;
|
||||||
float scale;
|
float originPower, originScale, originShift;
|
||||||
float shift;
|
|
||||||
|
|
||||||
explicit PowerFunctor(float power_ = 1.f, float scale_ = 1.f, float shift_ = 0.f)
|
explicit PowerFunctor(float power_ = 1.f, float scale_ = 1.f, float shift_ = 0.f)
|
||||||
: power(power_), scale(scale_), shift(shift_) {}
|
: power(power_), scale(scale_), shift(shift_),
|
||||||
|
originPower(power_), originScale(scale_), originShift(shift_) {}
|
||||||
|
|
||||||
bool supportBackend(int backendId, int targetId)
|
bool supportBackend(int backendId, int targetId)
|
||||||
{
|
{
|
||||||
@ -1083,6 +1056,13 @@ struct PowerFunctor
|
|||||||
return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_HALIDE || backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH;
|
return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_HALIDE || backendId == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void finalize()
|
||||||
|
{
|
||||||
|
power = originPower;
|
||||||
|
scale = originScale;
|
||||||
|
shift = originShift;
|
||||||
|
}
|
||||||
|
|
||||||
void apply(const float* srcptr, float* dstptr, int len, size_t planeSize, int cn0, int cn1) const
|
void apply(const float* srcptr, float* dstptr, int len, size_t planeSize, int cn0, int cn1) const
|
||||||
{
|
{
|
||||||
float a = scale, b = shift, p = power;
|
float a = scale, b = shift, p = power;
|
||||||
@ -1212,8 +1192,7 @@ struct PowerFunctor
|
|||||||
int64 getFLOPSPerElement() const { return power == 1 ? 2 : 10; }
|
int64 getFLOPSPerElement() const { return power == 1 ? 2 : 10; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ChannelsPReLUFunctor : public BaseFunctor
|
||||||
struct ChannelsPReLUFunctor
|
|
||||||
{
|
{
|
||||||
typedef ChannelsPReLULayer Layer;
|
typedef ChannelsPReLULayer Layer;
|
||||||
Mat scale;
|
Mat scale;
|
||||||
@ -1330,11 +1309,6 @@ struct ChannelsPReLUFunctor
|
|||||||
}
|
}
|
||||||
#endif // HAVE_DNN_NGRAPH
|
#endif // HAVE_DNN_NGRAPH
|
||||||
|
|
||||||
|
|
||||||
bool tryFuse(Ptr<dnn::Layer>&) { return false; }
|
|
||||||
|
|
||||||
void getScaleShift(Mat&, Mat&) const {}
|
|
||||||
|
|
||||||
int64 getFLOPSPerElement() const { return 1; }
|
int64 getFLOPSPerElement() const { return 1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user