mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Merge branch 4.x
This commit is contained in:
@@ -165,6 +165,40 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
int outputNameToIndex(const String& outputName) CV_OVERRIDE;
|
||||
};
|
||||
|
||||
/** @brief GRU recurrent one-layer
|
||||
*
|
||||
* Accepts input sequence and computes the final hidden state for each element in the batch.
|
||||
*
|
||||
* - input[0] containing the features of the input sequence.
|
||||
* input[0] should have shape [`T`, `N`, `data_dims`] where `T` is sequence length, `N` is batch size, `data_dims` is input size
|
||||
* - output would have shape [`T`, `N`, `D` * `hidden_size`] where `D = 2` if layer is bidirectional otherwise `D = 1`
|
||||
*
|
||||
* Depends on the following attributes:
|
||||
* - hidden_size - Number of neurons in the hidden layer
|
||||
* - direction - RNN could be bidirectional or forward
|
||||
*
|
||||
* The final hidden state @f$ h_t @f$ computes by the following formulas:
|
||||
*
|
||||
@f{eqnarray*}{
|
||||
r_t = \sigma(W_{ir} x_t + b_{ir} + W_{hr} h_{(t-1)} + b_{hr}) \\
|
||||
z_t = \sigma(W_{iz} x_t + b_{iz} + W_{hz} h_{(t-1)} + b_{hz}) \\
|
||||
n_t = \tanh(W_{in} x_t + b_{in} + r_t \odot (W_{hn} h_{(t-1)}+ b_{hn})) \\
|
||||
h_t = (1 - z_t) \odot n_t + z_t \odot h_{(t-1)} \\
|
||||
@f}
|
||||
* Where @f$x_t@f$ is current input, @f$h_{(t-1)}@f$ is previous or initial hidden state.
|
||||
*
|
||||
* @f$W_{x?}@f$, @f$W_{h?}@f$ and @f$b_{?}@f$ are learned weights represented as matrices:
|
||||
* @f$W_{x?} \in R^{N_h \times N_x}@f$, @f$W_{h?} \in R^{N_h \times N_h}@f$, @f$b_? \in R^{N_h}@f$.
|
||||
*
|
||||
* @f$\odot@f$ is per-element multiply operation.
|
||||
*/
|
||||
class CV_EXPORTS GRULayer : public Layer
|
||||
{
|
||||
public:
|
||||
/** Creates instance of GRU layer */
|
||||
static Ptr<GRULayer> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
/** @brief Classical recurrent layer
|
||||
|
||||
Accepts two inputs @f$x_t@f$ and @f$h_{t-1}@f$ and compute two outputs @f$o_t@f$ and @f$h_t@f$.
|
||||
@@ -224,6 +258,14 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
static Ptr<BaseConvolutionLayer> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
class CV_EXPORTS ConvolutionLayerInt8 : public BaseConvolutionLayer
|
||||
{
|
||||
public:
|
||||
int input_zp, output_zp;
|
||||
float output_sc;
|
||||
static Ptr<BaseConvolutionLayer> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
class CV_EXPORTS DeconvolutionLayer : public BaseConvolutionLayer
|
||||
{
|
||||
public:
|
||||
@@ -266,6 +308,13 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
static Ptr<PoolingLayer> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
class CV_EXPORTS PoolingLayerInt8 : public PoolingLayer
|
||||
{
|
||||
public:
|
||||
int input_zp, output_zp;
|
||||
static Ptr<PoolingLayerInt8> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
class CV_EXPORTS SoftmaxLayer : public Layer
|
||||
{
|
||||
public:
|
||||
@@ -274,6 +323,14 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
static Ptr<SoftmaxLayer> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
class CV_EXPORTS SoftmaxLayerInt8 : public SoftmaxLayer
|
||||
{
|
||||
public:
|
||||
float output_sc;
|
||||
int output_zp;
|
||||
static Ptr<SoftmaxLayerInt8> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
class CV_EXPORTS InnerProductLayer : public Layer
|
||||
{
|
||||
public:
|
||||
@@ -281,6 +338,13 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
static Ptr<InnerProductLayer> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
class CV_EXPORTS InnerProductLayerInt8 : public InnerProductLayer
|
||||
{
|
||||
public:
|
||||
int output_zp;
|
||||
static Ptr<InnerProductLayerInt8> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
class CV_EXPORTS MVNLayer : public Layer
|
||||
{
|
||||
public:
|
||||
@@ -307,6 +371,29 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
static Ptr<FlattenLayer> create(const LayerParams ¶ms);
|
||||
};
|
||||
|
||||
class CV_EXPORTS QuantizeLayer : public Layer
|
||||
{
|
||||
public:
|
||||
float scale;
|
||||
int zeropoint;
|
||||
static Ptr<QuantizeLayer> create(const LayerParams ¶ms);
|
||||
};
|
||||
|
||||
class CV_EXPORTS DequantizeLayer : public Layer
|
||||
{
|
||||
public:
|
||||
float scale;
|
||||
int zeropoint;
|
||||
static Ptr<DequantizeLayer> create(const LayerParams ¶ms);
|
||||
};
|
||||
|
||||
class CV_EXPORTS RequantizeLayer : public Layer
|
||||
{
|
||||
public:
|
||||
float scale, shift;
|
||||
static Ptr<RequantizeLayer> create(const LayerParams ¶ms);
|
||||
};
|
||||
|
||||
class CV_EXPORTS ConcatLayer : public Layer
|
||||
{
|
||||
public:
|
||||
@@ -318,6 +405,7 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
* Details: https://github.com/torch/nn/blob/master/doc/containers.md#depthconcat
|
||||
*/
|
||||
bool padding;
|
||||
int paddingValue;
|
||||
|
||||
static Ptr<ConcatLayer> create(const LayerParams ¶ms);
|
||||
};
|
||||
@@ -425,7 +513,11 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
{
|
||||
public:
|
||||
virtual void forwardSlice(const float* src, float* dst, int len,
|
||||
size_t outPlaneSize, int cn0, int cn1) const = 0;
|
||||
size_t outPlaneSize, int cn0, int cn1) const {};
|
||||
virtual void forwardSlice(const int* src, const int* lut, int* dst, int len,
|
||||
size_t outPlaneSize, int cn0, int cn1) const {};
|
||||
virtual void forwardSlice(const int8_t* src, const int8_t* lut, int8_t* dst, int len,
|
||||
size_t outPlaneSize, int cn0, int cn1) const {};
|
||||
};
|
||||
|
||||
class CV_EXPORTS ReLULayer : public ActivationLayer
|
||||
@@ -508,6 +600,12 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
static Ptr<ExpLayer> create(const LayerParams ¶ms);
|
||||
};
|
||||
|
||||
class CV_EXPORTS ActivationLayerInt8 : public ActivationLayer
|
||||
{
|
||||
public:
|
||||
static Ptr<ActivationLayerInt8> create(const LayerParams ¶ms);
|
||||
};
|
||||
|
||||
/* Layers used in semantic segmentation */
|
||||
|
||||
class CV_EXPORTS CropLayer : public Layer
|
||||
@@ -519,7 +617,7 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
/** @brief Element wise operation on inputs
|
||||
|
||||
Extra optional parameters:
|
||||
- "operation" as string. Values are "sum" (default), "prod", "max", "div"
|
||||
- "operation" as string. Values are "sum" (default), "prod", "max", "div", "min"
|
||||
- "coeff" as float array. Specify weights of inputs for SUM operation
|
||||
- "output_channels_mode" as string. Values are "same" (default, all input must have the same layout), "input_0", "input_0_truncate", "max_input_channels"
|
||||
*/
|
||||
@@ -529,6 +627,12 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
static Ptr<EltwiseLayer> create(const LayerParams ¶ms);
|
||||
};
|
||||
|
||||
class CV_EXPORTS EltwiseLayerInt8 : public Layer
|
||||
{
|
||||
public:
|
||||
static Ptr<EltwiseLayerInt8> create(const LayerParams ¶ms);
|
||||
};
|
||||
|
||||
class CV_EXPORTS BatchNormLayer : public ActivationLayer
|
||||
{
|
||||
public:
|
||||
@@ -538,6 +642,14 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
static Ptr<BatchNormLayer> create(const LayerParams ¶ms);
|
||||
};
|
||||
|
||||
class CV_EXPORTS BatchNormLayerInt8 : public BatchNormLayer
|
||||
{
|
||||
public:
|
||||
float input_sc, output_sc;
|
||||
int input_zp, output_zp;
|
||||
static Ptr<BatchNormLayerInt8> create(const LayerParams ¶ms);
|
||||
};
|
||||
|
||||
class CV_EXPORTS MaxUnpoolLayer : public Layer
|
||||
{
|
||||
public:
|
||||
@@ -557,12 +669,26 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
static Ptr<ScaleLayer> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
class CV_EXPORTS ScaleLayerInt8 : public ScaleLayer
|
||||
{
|
||||
public:
|
||||
float output_sc;
|
||||
int output_zp;
|
||||
static Ptr<ScaleLayerInt8> create(const LayerParams ¶ms);
|
||||
};
|
||||
|
||||
class CV_EXPORTS ShiftLayer : public Layer
|
||||
{
|
||||
public:
|
||||
static Ptr<Layer> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
class CV_EXPORTS ShiftLayerInt8 : public Layer
|
||||
{
|
||||
public:
|
||||
static Ptr<Layer> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
class CV_EXPORTS DataAugmentationLayer : public Layer
|
||||
{
|
||||
public:
|
||||
@@ -689,6 +815,15 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
static Ptr<Layer> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
class CV_EXPORTS CumSumLayer : public Layer
|
||||
{
|
||||
public:
|
||||
int exclusive;
|
||||
int reverse;
|
||||
|
||||
static Ptr<CumSumLayer> create(const LayerParams& params);
|
||||
};
|
||||
|
||||
//! @}
|
||||
//! @}
|
||||
CV__DNN_INLINE_NS_END
|
||||
|
||||
@@ -235,6 +235,15 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
*/
|
||||
virtual void forward(InputArrayOfArrays inputs, OutputArrayOfArrays outputs, OutputArrayOfArrays internals);
|
||||
|
||||
/** @brief Tries to quantize the given layer and compute the quantization parameters required for fixed point implementation.
|
||||
* @param[in] scales input and output scales.
|
||||
* @param[in] zeropoints input and output zeropoints.
|
||||
* @param[out] params Quantized parameters required for fixed point implementation of that layer.
|
||||
* @returns True if layer can be quantized.
|
||||
*/
|
||||
virtual bool tryQuantize(const std::vector<std::vector<float> > &scales,
|
||||
const std::vector<std::vector<int> > &zeropoints, LayerParams& params);
|
||||
|
||||
/** @brief Given the @p input blobs, computes the output @p blobs.
|
||||
* @param[in] inputs the input blobs.
|
||||
* @param[out] outputs allocated output blobs, which will store results of the computation.
|
||||
@@ -368,6 +377,16 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
*/
|
||||
virtual void getScaleShift(Mat& scale, Mat& shift) const;
|
||||
|
||||
/**
|
||||
* @brief Returns scale and zeropoint of layers
|
||||
* @param[out] scale Output scale
|
||||
* @param[out] zeropoint Output zeropoint
|
||||
*
|
||||
* By default, @p scale is 1 and @p zeropoint is 0.
|
||||
*/
|
||||
virtual void getScaleZeropoint(float& scale, int& zeropoint) const;
|
||||
|
||||
|
||||
/**
|
||||
* @brief "Deattaches" all the layers, attached to particular layer.
|
||||
*/
|
||||
@@ -453,13 +472,21 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
/** @brief Adds new layer to the net.
|
||||
* @param name unique name of the adding layer.
|
||||
* @param type typename of the adding layer (type must be registered in LayerRegister).
|
||||
* @param dtype datatype of output blobs.
|
||||
* @param params parameters which will be used to initialize the creating layer.
|
||||
* @returns unique identifier of created layer, or -1 if a failure will happen.
|
||||
*/
|
||||
int addLayer(const String &name, const String &type, const int &dtype, LayerParams ¶ms);
|
||||
|
||||
/** @overload Datatype of output blobs set to default CV_32F */
|
||||
int addLayer(const String &name, const String &type, LayerParams ¶ms);
|
||||
|
||||
/** @brief Adds new layer and connects its first input to the first output of previously added layer.
|
||||
* @see addLayer()
|
||||
*/
|
||||
int addLayerToPrev(const String &name, const String &type, const int &dtype, LayerParams ¶ms);
|
||||
|
||||
/** @overload */
|
||||
int addLayerToPrev(const String &name, const String &type, LayerParams ¶ms);
|
||||
|
||||
/** @brief Converts string name of the layer to the integer identifier.
|
||||
@@ -551,6 +578,25 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
CV_WRAP_AS(forwardAndRetrieve) void forward(CV_OUT std::vector<std::vector<Mat> >& outputBlobs,
|
||||
const std::vector<String>& outBlobNames);
|
||||
|
||||
/** @brief Returns a quantized Net from a floating-point Net.
|
||||
* @param calibData Calibration data to compute the quantization parameters.
|
||||
* @param inputsDtype Datatype of quantized net's inputs. Can be CV_32F or CV_8S.
|
||||
* @param outputsDtype Datatype of quantized net's outputs. Can be CV_32F or CV_8S.
|
||||
*/
|
||||
CV_WRAP Net quantize(InputArrayOfArrays calibData, int inputsDtype, int outputsDtype);
|
||||
|
||||
/** @brief Returns input scale and zeropoint for a quantized Net.
|
||||
* @param scales output parameter for returning input scales.
|
||||
* @param zeropoints output parameter for returning input zeropoints.
|
||||
*/
|
||||
CV_WRAP void getInputDetails(CV_OUT std::vector<float>& scales, CV_OUT std::vector<int>& zeropoints) const;
|
||||
|
||||
/** @brief Returns output scale and zeropoint for a quantized Net.
|
||||
* @param scales output parameter for returning output scales.
|
||||
* @param zeropoints output parameter for returning output zeropoints.
|
||||
*/
|
||||
CV_WRAP void getOutputDetails(CV_OUT std::vector<float>& scales, CV_OUT std::vector<int>& zeropoints) const;
|
||||
|
||||
/**
|
||||
* @brief Compile Halide layers.
|
||||
* @param[in] scheduler Path to YAML file with scheduling directives.
|
||||
@@ -1084,6 +1130,39 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
CV_OUT std::vector<int>& indices,
|
||||
const float eta = 1.f, const int top_k = 0);
|
||||
|
||||
/**
|
||||
* @brief Enum of Soft NMS methods.
|
||||
* @see softNMSBoxes
|
||||
*/
|
||||
enum class SoftNMSMethod
|
||||
{
|
||||
SOFTNMS_LINEAR = 1,
|
||||
SOFTNMS_GAUSSIAN = 2
|
||||
};
|
||||
|
||||
/** @brief Performs soft non maximum suppression given boxes and corresponding scores.
|
||||
* Reference: https://arxiv.org/abs/1704.04503
|
||||
* @param bboxes a set of bounding boxes to apply Soft NMS.
|
||||
* @param scores a set of corresponding confidences.
|
||||
* @param updated_scores a set of corresponding updated confidences.
|
||||
* @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 top_k keep at most @p top_k picked indices.
|
||||
* @param sigma parameter of Gaussian weighting.
|
||||
* @param method Gaussian or linear.
|
||||
* @see SoftNMSMethod
|
||||
*/
|
||||
CV_EXPORTS_W void softNMSBoxes(const std::vector<Rect>& bboxes,
|
||||
const std::vector<float>& scores,
|
||||
CV_OUT std::vector<float>& updated_scores,
|
||||
const float score_threshold,
|
||||
const float nms_threshold,
|
||||
CV_OUT std::vector<int>& indices,
|
||||
size_t top_k = 0,
|
||||
const float sigma = 0.5,
|
||||
SoftNMSMethod method = SoftNMSMethod::SOFTNMS_GAUSSIAN);
|
||||
|
||||
|
||||
/** @brief This class is presented high-level API for neural networks.
|
||||
*
|
||||
@@ -1373,7 +1452,9 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Set the decoding method of translating the network output into string
|
||||
* @param[in] decodeType The decoding method of translating the network output into string: {'CTC-greedy': greedy decoding for the output of CTC-based methods}
|
||||
* @param[in] decodeType The decoding method of translating the network output into string, currently supported type:
|
||||
* - `"CTC-greedy"` greedy decoding for the output of CTC-based methods
|
||||
* - `"CTC-prefix-beam-search"` Prefix beam search decoding for the output of CTC-based methods
|
||||
*/
|
||||
CV_WRAP
|
||||
TextRecognitionModel& setDecodeType(const std::string& decodeType);
|
||||
@@ -1385,6 +1466,15 @@ public:
|
||||
CV_WRAP
|
||||
const std::string& getDecodeType() const;
|
||||
|
||||
/**
|
||||
* @brief Set the decoding method options for `"CTC-prefix-beam-search"` decode usage
|
||||
* @param[in] beamSize Beam size for search
|
||||
* @param[in] vocPruneSize Parameter to optimize big vocabulary search,
|
||||
* only take top @p vocPruneSize tokens in each search step, @p vocPruneSize <= 0 stands for disable this prune.
|
||||
*/
|
||||
CV_WRAP
|
||||
TextRecognitionModel& setDecodeOptsCTCPrefixBeamSearch(int beamSize, int vocPruneSize = 0);
|
||||
|
||||
/**
|
||||
* @brief Set the vocabulary for recognition.
|
||||
* @param[in] vocabulary the associated vocabulary of the network.
|
||||
|
||||
@@ -12,10 +12,16 @@ CV__DNN_INLINE_NS_BEGIN
|
||||
//! @addtogroup dnn
|
||||
//! @{
|
||||
|
||||
//! Register layer types of DNN model.
|
||||
typedef std::map<std::string, std::vector<LayerFactory::Constructor> > LayerFactory_Impl;
|
||||
|
||||
//! Register layer types of DNN model.
|
||||
//!
|
||||
//! @note In order to thread-safely access the factory, see getLayerFactoryMutex() function.
|
||||
LayerFactory_Impl& getLayerFactoryImpl();
|
||||
|
||||
//! Get the mutex guarding @ref LayerFactory_Impl, see getLayerFactoryImpl() function.
|
||||
Mutex& getLayerFactoryMutex();
|
||||
|
||||
//! @}
|
||||
CV__DNN_INLINE_NS_END
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
#ifndef OPENCV_DNN_UTILS_DEBUG_UTILS_HPP
|
||||
#define OPENCV_DNN_UTILS_DEBUG_UTILS_HPP
|
||||
|
||||
#include "../dnn.hpp"
|
||||
|
||||
namespace cv { namespace dnn {
|
||||
CV__DNN_INLINE_NS_BEGIN
|
||||
|
||||
/**
|
||||
* @brief Skip model import after diagnostic run in readNet() functions.
|
||||
* @param[in] skip Indicates whether to skip the import.
|
||||
*
|
||||
* This is an internal OpenCV function not intended for users.
|
||||
*/
|
||||
CV_EXPORTS void skipModelImport(bool skip);
|
||||
|
||||
CV__DNN_INLINE_NS_END
|
||||
}} // namespace
|
||||
|
||||
#endif // OPENCV_DNN_UTILS_DEBUG_UTILS_HPP
|
||||
@@ -6,7 +6,7 @@
|
||||
#define OPENCV_DNN_VERSION_HPP
|
||||
|
||||
/// Use with major OpenCV version only.
|
||||
#define OPENCV_DNN_API_VERSION 20210608
|
||||
#define OPENCV_DNN_API_VERSION 20211015
|
||||
|
||||
#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)
|
||||
|
||||
Reference in New Issue
Block a user