1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 00:03:03 +04:00

Merge branch 4.x

This commit is contained in:
Alexander Alekhin
2023-01-09 11:08:02 +00:00
880 changed files with 83958 additions and 9368 deletions
+35 -4
View File
@@ -256,6 +256,10 @@ CV__DNN_INLINE_NS_BEGIN
{
public:
static Ptr<BaseConvolutionLayer> create(const LayerParams& params);
bool fusedActivation = false;
bool fusedAdd = false;
bool isConv2D = false; // Should be deleted after fastconv branch support Conv1D and Conv3D.
bool useWinograd = false; // Flag whether to use Winograd to speed up 3x3 convolution.
};
class CV_EXPORTS ConvolutionLayerInt8 : public BaseConvolutionLayer
@@ -267,6 +271,7 @@ CV__DNN_INLINE_NS_BEGIN
// quantization type flag. The perChannel default is true, that means it contains the parameters
// of per-Channel quantization. Otherwise, that means this layer contains per-Tensor quantized parameters.
bool per_channel;
bool useWinograd = true; // Flag whether to use Winograd to speed up 3x3 convolution.
static Ptr<BaseConvolutionLayer> create(const LayerParams& params);
};
@@ -298,6 +303,14 @@ CV__DNN_INLINE_NS_BEGIN
static Ptr<ArgLayer> create(const LayerParams& params);
};
/** @brief Gather layer
*/
class CV_EXPORTS GatherLayer : public Layer
{
public:
static Ptr<GatherLayer> create(const LayerParams& params);
};
class CV_EXPORTS PoolingLayer : public Layer
{
public:
@@ -409,16 +422,16 @@ CV__DNN_INLINE_NS_BEGIN
class CV_EXPORTS QuantizeLayer : public Layer
{
public:
float scale;
int zeropoint;
std::vector<float> scales;
std::vector<int> zeropoints;
static Ptr<QuantizeLayer> create(const LayerParams &params);
};
class CV_EXPORTS DequantizeLayer : public Layer
{
public:
float scale;
int zeropoint;
std::vector<float> scales;
std::vector<int> zeropoints;
static Ptr<DequantizeLayer> create(const LayerParams &params);
};
@@ -1054,6 +1067,24 @@ CV__DNN_INLINE_NS_BEGIN
static Ptr<CumSumLayer> create(const LayerParams& params);
};
class CV_EXPORTS ScatterLayer : public Layer
{
public:
static Ptr<ScatterLayer> create(const LayerParams& params);
};
class CV_EXPORTS ScatterNDLayer : public Layer
{
public:
static Ptr<ScatterNDLayer> create(const LayerParams& params);
};
class CV_EXPORTS TileLayer : public Layer
{
public:
static Ptr<TileLayer> create(const LayerParams& params);
};
//! @}
//! @}
CV__DNN_INLINE_NS_END
+53 -5
View File
@@ -52,6 +52,11 @@
namespace cv {
namespace dnn {
namespace accessor {
class DnnNetAccessor; // forward declaration
}
CV__DNN_INLINE_NS_BEGIN
//! @addtogroup dnn
//! @{
@@ -65,20 +70,23 @@ CV__DNN_INLINE_NS_BEGIN
enum Backend
{
//! DNN_BACKEND_DEFAULT equals to DNN_BACKEND_INFERENCE_ENGINE if
//! OpenCV is built with Intel's Inference Engine library or
//! OpenCV is built with Intel OpenVINO or
//! DNN_BACKEND_OPENCV otherwise.
DNN_BACKEND_DEFAULT = 0,
DNN_BACKEND_HALIDE,
DNN_BACKEND_INFERENCE_ENGINE, //!< Intel's Inference Engine computational backend
//!< @sa setInferenceEngineBackendType
DNN_BACKEND_INFERENCE_ENGINE, //!< Intel OpenVINO computational backend
//!< @note Tutorial how to build OpenCV with OpenVINO: @ref tutorial_dnn_openvino
DNN_BACKEND_OPENCV,
DNN_BACKEND_VKCOM,
DNN_BACKEND_CUDA,
DNN_BACKEND_WEBNN,
DNN_BACKEND_TIMVX,
#ifdef __OPENCV_BUILD
DNN_BACKEND_CANN,
#if defined(__OPENCV_BUILD) || defined(BUILD_PLUGIN)
#if !defined(OPENCV_BINDING_PARSER)
DNN_BACKEND_INFERENCE_ENGINE_NGRAPH = 1000000, // internal - use DNN_BACKEND_INFERENCE_ENGINE + setInferenceEngineBackendType()
DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019, // internal - use DNN_BACKEND_INFERENCE_ENGINE + setInferenceEngineBackendType()
#endif
#endif
};
@@ -336,6 +344,15 @@ CV__DNN_INLINE_NS_BEGIN
const std::vector<Ptr<BackendWrapper> > &outputsWrapper,
bool isLast);
/**
* @brief Returns a CANN backend node
*
* @param inputsWrapper layer inputs
* @param index layer id for op name
* @param nodes inputs of this node
*/
virtual Ptr<BackendNode> initCann(const std::vector<Ptr<BackendWrapper> > &inputsWrapper, const int index, const std::vector<Ptr<BackendNode> >& nodes);
/**
* @brief Automatic Halide scheduling based on layer hyper-parameters.
* @param[in] node Backend node with Halide functions.
@@ -830,6 +847,12 @@ CV__DNN_INLINE_NS_BEGIN
*/
CV_WRAP void enableFusion(bool fusion);
/** @brief Enables or disables the Winograd compute branch. The Winograd compute branch can speed up
* 3x3 Convolution at a small loss of accuracy.
* @param useWinograd true to enable the Winograd compute branch. The default is true.
*/
CV_WRAP void enableWinograd(bool useWinograd);
/** @brief Returns overall time for inference and timings (in ticks) for layers.
*
* Indexes in returned vector correspond to layers ids. Some layers can be fused with others,
@@ -840,8 +863,12 @@ CV__DNN_INLINE_NS_BEGIN
*/
CV_WRAP int64 getPerfProfile(CV_OUT std::vector<double>& timings);
private:
struct Impl;
inline Impl* getImpl() const { return impl.get(); }
inline Impl& getImplRef() const { CV_DbgAssert(impl); return *impl.get(); }
friend class accessor::DnnNetAccessor;
protected:
Ptr<Impl> impl;
};
@@ -1177,6 +1204,27 @@ CV__DNN_INLINE_NS_BEGIN
CV_OUT std::vector<int>& indices,
const float eta = 1.f, const int top_k = 0);
/** @brief Performs batched non maximum suppression on given boxes and corresponding scores across different classes.
* @param bboxes a set of bounding boxes to apply NMS.
* @param scores a set of corresponding confidences.
* @param class_ids a set of corresponding class ids. Ids are integer and usually start from 0.
* @param score_threshold a threshold used to filter boxes by score.
* @param nms_threshold a threshold used in non maximum suppression.
* @param indices the kept indices of bboxes after NMS.
* @param eta a coefficient in adaptive threshold formula: \f$nms\_threshold_{i+1}=eta\cdot nms\_threshold_i\f$.
* @param top_k if `>0`, keep at most @p top_k picked indices.
*/
CV_EXPORTS void NMSBoxesBatched(const std::vector<Rect>& bboxes, const std::vector<float>& scores, const std::vector<int>& class_ids,
const float score_threshold, const float nms_threshold,
CV_OUT std::vector<int>& indices,
const float eta = 1.f, const int top_k = 0);
CV_EXPORTS_W void NMSBoxesBatched(const std::vector<Rect2d>& bboxes, const std::vector<float>& scores, const std::vector<int>& class_ids,
const float score_threshold, const float nms_threshold,
CV_OUT std::vector<int>& indices,
const float eta = 1.f, const int top_k = 0);
/**
* @brief Enum of Soft NMS methods.
* @see softNMSBoxes
@@ -160,22 +160,49 @@ static inline MatShape shape(int a0, int a1=-1, int a2=-1, int a3=-1)
static inline int total(const MatShape& shape, int start = -1, int end = -1)
{
if (start == -1) start = 0;
if (end == -1) end = (int)shape.size();
if (shape.empty())
return 0;
int dims = (int)shape.size();
if (start == -1) start = 0;
if (end == -1) end = dims;
CV_CheckLE(0, start, "");
CV_CheckLE(start, end, "");
CV_CheckLE(end, dims, "");
int elems = 1;
CV_Assert(start <= (int)shape.size() && end <= (int)shape.size() &&
start <= end);
for(int i = start; i < end; i++)
for (int i = start; i < end; i++)
{
elems *= shape[i];
}
return elems;
}
// TODO: rename to countDimsElements()
static inline int total(const Mat& mat, int start = -1, int end = -1)
{
if (mat.empty())
return 0;
int dims = mat.dims;
if (start == -1) start = 0;
if (end == -1) end = dims;
CV_CheckLE(0, start, "");
CV_CheckLE(start, end, "");
CV_CheckLE(end, dims, "");
int elems = 1;
for (int i = start; i < end; i++)
{
elems *= mat.size[i];
}
return elems;
}
static inline MatShape concat(const MatShape& a, const MatShape& b)
{
MatShape c = a;
+1 -1
View File
@@ -6,7 +6,7 @@
#define OPENCV_DNN_VERSION_HPP
/// Use with major OpenCV version only.
#define OPENCV_DNN_API_VERSION 20220821
#define OPENCV_DNN_API_VERSION 20221220
#if !defined CV_DOXYGEN && !defined CV_STATIC_ANALYSIS && !defined CV_DNN_DONT_ADD_INLINE_NS
#define CV__DNN_INLINE_NS __CV_CAT(dnn5_v, OPENCV_DNN_API_VERSION)