1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of the copyright holders may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
42 #ifndef OPENCV_DNN_DNN_ALL_LAYERS_HPP
43 #define OPENCV_DNN_DNN_ALL_LAYERS_HPP
44 #include <opencv2/dnn.hpp>
48 CV__DNN_INLINE_NS_BEGIN
52 /** @defgroup dnnLayerList Partial List of Implemented Layers
54 This subsection of dnn module contains information about built-in layers and their descriptions.
56 Classes listed here, in fact, provides C++ API for creating instances of built-in layers.
57 In addition to this way of layers instantiation, there is a more common factory API (see @ref dnnLayerFactory), it allows to create layers dynamically (by name) and register new ones.
58 You can use both API, but factory API is less convenient for native C++ programming and basically designed for use inside importers (see @ref readNetFromCaffe(), @ref readNetFromTorch(), @ref readNetFromTensorflow()).
60 Built-in layers partially reproduce functionality of corresponding Caffe and Torch7 layers.
61 In particular, the following layers and Caffe importer were tested to reproduce <a href="http://caffe.berkeleyvision.org/tutorial/layers.html">Caffe</a> functionality:
66 - TanH, ReLU, Sigmoid, BNLL, Power, AbsVal
68 - Reshape, Flatten, Slice, Split
71 - Dropout (since it does nothing on forward pass -))
74 class CV_EXPORTS BlankLayer : public Layer
77 static Ptr<Layer> create(const LayerParams ¶ms);
81 * Constant layer produces the same data blob at an every forward pass.
83 class CV_EXPORTS ConstLayer : public Layer
86 static Ptr<Layer> create(const LayerParams ¶ms);
89 //! LSTM recurrent layer
90 class CV_EXPORTS LSTMLayer : public Layer
93 /** Creates instance of LSTM layer */
94 static Ptr<LSTMLayer> create(const LayerParams& params);
96 /** @deprecated Use LayerParams::blobs instead.
97 @brief Set trained weights for LSTM layer.
99 LSTM behavior on each step is defined by current input, previous output, previous cell state and learned weights.
101 Let @f$x_t@f$ be current input, @f$h_t@f$ be current output, @f$c_t@f$ be current state.
102 Than current output and current cell state is computed as follows:
104 h_t &= o_t \odot tanh(c_t), \\
105 c_t &= f_t \odot c_{t-1} + i_t \odot g_t, \\
107 where @f$\odot@f$ is per-element multiply operation and @f$i_t, f_t, o_t, g_t@f$ is internal gates that are computed using learned weights.
109 Gates are computed as follows:
111 i_t &= sigmoid&(W_{xi} x_t + W_{hi} h_{t-1} + b_i), \\
112 f_t &= sigmoid&(W_{xf} x_t + W_{hf} h_{t-1} + b_f), \\
113 o_t &= sigmoid&(W_{xo} x_t + W_{ho} h_{t-1} + b_o), \\
114 g_t &= tanh &(W_{xg} x_t + W_{hg} h_{t-1} + b_g), \\
116 where @f$W_{x?}@f$, @f$W_{h?}@f$ and @f$b_{?}@f$ are learned weights represented as matrices:
117 @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$.
119 For simplicity and performance purposes we use @f$ W_x = [W_{xi}; W_{xf}; W_{xo}, W_{xg}] @f$
120 (i.e. @f$W_x@f$ is vertical concatenation of @f$ W_{x?} @f$), @f$ W_x \in R^{4N_h \times N_x} @f$.
121 The same for @f$ W_h = [W_{hi}; W_{hf}; W_{ho}, W_{hg}], W_h \in R^{4N_h \times N_h} @f$
122 and for @f$ b = [b_i; b_f, b_o, b_g]@f$, @f$b \in R^{4N_h} @f$.
124 @param Wh is matrix defining how previous output is transformed to internal gates (i.e. according to above mentioned notation is @f$ W_h @f$)
125 @param Wx is matrix defining how current input is transformed to internal gates (i.e. according to above mentioned notation is @f$ W_x @f$)
126 @param b is bias vector (i.e. according to above mentioned notation is @f$ b @f$)
128 CV_DEPRECATED virtual void setWeights(const Mat &Wh, const Mat &Wx, const Mat &b) = 0;
130 /** @brief Specifies shape of output blob which will be [[`T`], `N`] + @p outTailShape.
131 * @details If this parameter is empty or unset then @p outTailShape = [`Wh`.size(0)] will be used,
132 * where `Wh` is parameter from setWeights().
134 virtual void setOutShape(const MatShape &outTailShape = MatShape()) = 0;
136 /** @deprecated Use flag `produce_cell_output` in LayerParams.
137 * @brief Specifies either interpret first dimension of input blob as timestamp dimension either as sample.
139 * If flag is set to true then shape of input blob will be interpreted as [`T`, `N`, `[data dims]`] where `T` specifies number of timestamps, `N` is number of independent streams.
140 * In this case each forward() call will iterate through `T` timestamps and update layer's state `T` times.
142 * If flag is set to false then shape of input blob will be interpreted as [`N`, `[data dims]`].
143 * In this case each forward() call will make one iteration and produce one timestamp with shape [`N`, `[out dims]`].
145 CV_DEPRECATED virtual void setUseTimstampsDim(bool use = true) = 0;
147 /** @deprecated Use flag `use_timestamp_dim` in LayerParams.
148 * @brief If this flag is set to true then layer will produce @f$ c_t @f$ as second output.
149 * @details Shape of the second output is the same as first output.
151 CV_DEPRECATED virtual void setProduceCellOutput(bool produce = false) = 0;
153 /* In common case it use single input with @f$x_t@f$ values to compute output(s) @f$h_t@f$ (and @f$c_t@f$).
154 * @param input should contain packed values @f$x_t@f$
155 * @param output contains computed outputs: @f$h_t@f$ (and @f$c_t@f$ if setProduceCellOutput() flag was set to true).
157 * If setUseTimstampsDim() is set to true then @p input[0] should has at least two dimensions with the following shape: [`T`, `N`, `[data dims]`],
158 * where `T` specifies number of timestamps, `N` is number of independent streams (i.e. @f$ x_{t_0 + t}^{stream} @f$ is stored inside @p input[0][t, stream, ...]).
160 * If setUseTimstampsDim() is set to false then @p input[0] should contain single timestamp, its shape should has form [`N`, `[data dims]`] with at least one dimension.
161 * (i.e. @f$ x_{t}^{stream} @f$ is stored inside @p input[0][stream, ...]).
164 int inputNameToIndex(String inputName) CV_OVERRIDE;
165 int outputNameToIndex(const String& outputName) CV_OVERRIDE;
168 /** @brief GRU recurrent one-layer
170 * Accepts input sequence and computes the final hidden state for each element in the batch.
172 * - input[0] containing the features of the input sequence.
173 * input[0] should have shape [`T`, `N`, `data_dims`] where `T` is sequence length, `N` is batch size, `data_dims` is input size
174 * - output would have shape [`T`, `N`, `D` * `hidden_size`] where `D = 2` if layer is bidirectional otherwise `D = 1`
176 * Depends on the following attributes:
177 * - hidden_size - Number of neurons in the hidden layer
178 * - direction - RNN could be bidirectional or forward
180 * The final hidden state @f$ h_t @f$ computes by the following formulas:
183 r_t = \sigma(W_{ir} x_t + b_{ir} + W_{hr} h_{(t-1)} + b_{hr}) \\
184 z_t = \sigma(W_{iz} x_t + b_{iz} + W_{hz} h_{(t-1)} + b_{hz}) \\
185 n_t = \tanh(W_{in} x_t + b_{in} + r_t \odot (W_{hn} h_{(t-1)}+ b_{hn})) \\
186 h_t = (1 - z_t) \odot n_t + z_t \odot h_{(t-1)} \\
188 * Where @f$x_t@f$ is current input, @f$h_{(t-1)}@f$ is previous or initial hidden state.
190 * @f$W_{x?}@f$, @f$W_{h?}@f$ and @f$b_{?}@f$ are learned weights represented as matrices:
191 * @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$.
193 * @f$\odot@f$ is per-element multiply operation.
195 class CV_EXPORTS GRULayer : public Layer
198 /** Creates instance of GRU layer */
199 static Ptr<GRULayer> create(const LayerParams& params);
202 /** @brief Classical recurrent layer
204 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$.
206 - input: should contain packed input @f$x_t@f$.
207 - output: should contain output @f$o_t@f$ (and @f$h_t@f$ if setProduceHiddenOutput() is set to true).
209 input[0] should have shape [`T`, `N`, `data_dims`] where `T` and `N` is number of timestamps and number of independent samples of @f$x_t@f$ respectively.
211 output[0] will have shape [`T`, `N`, @f$N_o@f$], where @f$N_o@f$ is number of rows in @f$ W_{xo} @f$ matrix.
213 If setProduceHiddenOutput() is set to true then @p output[1] will contain a Mat with shape [`T`, `N`, @f$N_h@f$], where @f$N_h@f$ is number of rows in @f$ W_{hh} @f$ matrix.
215 class CV_EXPORTS RNNLayer : public Layer
218 /** Creates instance of RNNLayer */
219 static Ptr<RNNLayer> create(const LayerParams& params);
221 /** Setups learned weights.
223 Recurrent-layer behavior on each step is defined by current input @f$ x_t @f$, previous state @f$ h_t @f$ and learned weights as follows:
225 h_t &= tanh&(W_{hh} h_{t-1} + W_{xh} x_t + b_h), \\
226 o_t &= tanh&(W_{ho} h_t + b_o),
229 @param Wxh is @f$ W_{xh} @f$ matrix
230 @param bh is @f$ b_{h} @f$ vector
231 @param Whh is @f$ W_{hh} @f$ matrix
232 @param Who is @f$ W_{xo} @f$ matrix
233 @param bo is @f$ b_{o} @f$ vector
235 virtual void setWeights(const Mat &Wxh, const Mat &bh, const Mat &Whh, const Mat &Who, const Mat &bo) = 0;
237 /** @brief If this flag is set to true then layer will produce @f$ h_t @f$ as second output.
238 * @details Shape of the second output is the same as first output.
240 virtual void setProduceHiddenOutput(bool produce = false) = 0;
244 class CV_EXPORTS BaseConvolutionLayer : public Layer
247 CV_DEPRECATED_EXTERNAL Size kernel, stride, pad, dilation, adjustPad;
248 std::vector<size_t> adjust_pads;
249 std::vector<size_t> kernel_size, strides, dilations;
250 std::vector<size_t> pads_begin, pads_end;
255 class CV_EXPORTS ConvolutionLayer : public BaseConvolutionLayer
258 static Ptr<BaseConvolutionLayer> create(const LayerParams& params);
259 bool fusedActivation = false;
260 bool fusedAdd = false;
261 bool isConv2D = false; // Should be deleted after fastconv branch support Conv1D and Conv3D.
262 bool useWinograd = false; // Flag whether to use Winograd to speed up 3x3 convolution.
265 class CV_EXPORTS ConvolutionLayerInt8 : public BaseConvolutionLayer
268 int input_zp, output_zp;
269 float input_sc, output_sc;
271 // quantization type flag. The perChannel default is true, that means it contains the parameters
272 // of per-Channel quantization. Otherwise, that means this layer contains per-Tensor quantized parameters.
274 bool useWinograd = true; // Flag whether to use Winograd to speed up 3x3 convolution.
275 static Ptr<BaseConvolutionLayer> create(const LayerParams& params);
278 class CV_EXPORTS DeconvolutionLayer : public BaseConvolutionLayer
281 static Ptr<BaseConvolutionLayer> create(const LayerParams& params);
284 class CV_EXPORTS LRNLayer : public Layer
290 float alpha, beta, bias;
293 static Ptr<LRNLayer> create(const LayerParams& params);
297 /** @brief ArgMax/ArgMin layer
298 * @note returns indices as floats, which means the supported range is [-2^24; 2^24]
300 class CV_EXPORTS ArgLayer : public Layer
303 static Ptr<ArgLayer> create(const LayerParams& params);
306 /** @brief Gather layer
308 class CV_EXPORTS GatherLayer : public Layer
311 static Ptr<GatherLayer> create(const LayerParams& params);
314 class CV_EXPORTS PoolingLayer : public Layer
318 std::vector<size_t> kernel_size, strides;
319 std::vector<size_t> pads_begin, pads_end;
320 bool globalPooling; //!< Flag is true if at least one of the axes is global pooled.
321 std::vector<bool> isGlobalPooling;
325 // If true for average pooling with padding, divide an every output region
326 // by a whole kernel area. Otherwise exclude zero padded values and divide
327 // by number of real values.
328 bool avePoolPaddedArea;
329 // ROIPooling parameters.
332 // PSROIPooling parameters.
333 int psRoiOutChannels;
335 static Ptr<PoolingLayer> create(const LayerParams& params);
338 class CV_EXPORTS PoolingLayerInt8 : public PoolingLayer
341 int input_zp, output_zp;
342 float input_sc, output_sc;
343 static Ptr<PoolingLayerInt8> create(const LayerParams& params);
346 class CV_EXPORTS ReduceLayer : public Layer
350 // reduceDims contains the dimensions that need to be reduced, targetDims is the target output dimension.
351 std::vector<size_t> reduceDims, targetDims;
352 static Ptr<ReduceLayer> create(const LayerParams& params);
355 class CV_EXPORTS ReduceLayerInt8 : public ReduceLayer
358 static Ptr<ReduceLayerInt8> create(const LayerParams& params);
361 class CV_EXPORTS SoftmaxLayer : public Layer
366 static Ptr<SoftmaxLayer> create(const LayerParams& params);
369 class CV_EXPORTS SoftmaxLayerInt8 : public SoftmaxLayer
374 static Ptr<SoftmaxLayerInt8> create(const LayerParams& params);
377 class CV_EXPORTS InnerProductLayer : public Layer
381 static Ptr<InnerProductLayer> create(const LayerParams& params);
384 class CV_EXPORTS InnerProductLayerInt8 : public InnerProductLayer
387 int input_zp, output_zp;
388 float input_sc, output_sc;
390 // quantization type flag. The perChannel default is true, that means it contains the parameters
391 // of per-Channel quantization. Otherwise, that means this layer contains per-Tensor quantized parameters.
393 static Ptr<InnerProductLayerInt8> create(const LayerParams& params);
396 class CV_EXPORTS MVNLayer : public Layer
400 bool normVariance, acrossChannels;
402 static Ptr<MVNLayer> create(const LayerParams& params);
407 class CV_EXPORTS ReshapeLayer : public Layer
410 MatShape newShapeDesc;
413 static Ptr<ReshapeLayer> create(const LayerParams& params);
416 class CV_EXPORTS FlattenLayer : public Layer
419 static Ptr<FlattenLayer> create(const LayerParams ¶ms);
422 class CV_EXPORTS QuantizeLayer : public Layer
425 std::vector<float> scales;
426 std::vector<int> zeropoints;
427 static Ptr<QuantizeLayer> create(const LayerParams ¶ms);
430 class CV_EXPORTS DequantizeLayer : public Layer
433 std::vector<float> scales;
434 std::vector<int> zeropoints;
435 static Ptr<DequantizeLayer> create(const LayerParams ¶ms);
438 class CV_EXPORTS RequantizeLayer : public Layer
442 static Ptr<RequantizeLayer> create(const LayerParams ¶ms);
445 class CV_EXPORTS ConcatLayer : public Layer
450 * @brief Add zero padding in case of concatenation of blobs with different
453 * Details: https://github.com/torch/nn/blob/master/doc/containers.md#depthconcat
458 static Ptr<ConcatLayer> create(const LayerParams ¶ms);
461 class CV_EXPORTS SplitLayer : public Layer
464 int outputsCount; //!< Number of copies that will be produced (is ignored when negative).
466 static Ptr<SplitLayer> create(const LayerParams ¶ms);
470 * Slice layer has several modes:
472 * @param[in] axis Axis of split operation
473 * @param[in] slice_point Array of split points
475 * Number of output blobs equals to number of split points plus one. The
476 * first blob is a slice on input from 0 to @p slice_point[0] - 1 by @p axis,
477 * the second output blob is a slice of input from @p slice_point[0] to
478 * @p slice_point[1] - 1 by @p axis and the last output blob is a slice of
479 * input from @p slice_point[-1] up to the end of @p axis size.
482 * @param begin Vector of start indices
483 * @param size Vector of sizes
485 * More convenient numpy-like slice. One and only output blob
486 * is a slice `input[begin[0]:begin[0]+size[0], begin[1]:begin[1]+size[1], ...]`
489 * @param axis Axis of split operation
491 * Split input blob on the equal parts by @p axis.
493 class CV_EXPORTS SliceLayer : public Layer
497 * @brief Vector of slice ranges.
499 * The first dimension equals number of output blobs.
500 * Inner vector has slice ranges for the first number of input dimensions.
502 std::vector<std::vector<Range> > sliceRanges;
503 std::vector<std::vector<int> > sliceSteps;
507 static Ptr<SliceLayer> create(const LayerParams ¶ms);
510 class CV_EXPORTS PermuteLayer : public Layer
513 static Ptr<PermuteLayer> create(const LayerParams& params);
517 * Permute channels of 4-dimensional input blob.
518 * @param group Number of groups to split input channels and pick in turns
521 * \f[ groupSize = \frac{number\ of\ channels}{group} \f]
522 * \f[ output(n, c, h, w) = input(n, groupSize \times (c \% group) + \lfloor \frac{c}{group} \rfloor, h, w) \f]
523 * Read more at https://arxiv.org/pdf/1707.01083.pdf
525 class CV_EXPORTS ShuffleChannelLayer : public Layer
528 static Ptr<Layer> create(const LayerParams& params);
534 * @brief Adds extra values for specific axes.
535 * @param paddings Vector of paddings in format
537 * [ pad_before, pad_after, // [0]th dimension
538 * pad_before, pad_after, // [1]st dimension
540 * pad_before, pad_after ] // [n]th dimension
542 * that represents number of padded values at every dimension
543 * starting from the first one. The rest of dimensions won't
545 * @param value Value to be padded. Defaults to zero.
546 * @param type Padding type: 'constant', 'reflect'
547 * @param input_dims Torch's parameter. If @p input_dims is not equal to the
548 * actual input dimensionality then the `[0]th` dimension
549 * is considered as a batch dimension and @p paddings are shifted
550 * to a one dimension. Defaults to `-1` that means padding
551 * corresponding to @p paddings.
553 class CV_EXPORTS PaddingLayer : public Layer
556 static Ptr<PaddingLayer> create(const LayerParams& params);
560 class CV_EXPORTS ActivationLayer : public Layer
563 virtual void forwardSlice(const float* src, float* dst, int len,
564 size_t outPlaneSize, int cn0, int cn1) const {};
565 virtual void forwardSlice(const int* src, const int* lut, int* dst, int len,
566 size_t outPlaneSize, int cn0, int cn1) const {};
567 virtual void forwardSlice(const int8_t* src, const int8_t* lut, int8_t* dst, int len,
568 size_t outPlaneSize, int cn0, int cn1) const {};
571 class CV_EXPORTS ReLULayer : public ActivationLayer
576 static Ptr<ReLULayer> create(const LayerParams ¶ms);
579 class CV_EXPORTS ReLU6Layer : public ActivationLayer
582 float minValue, maxValue;
584 static Ptr<ReLU6Layer> create(const LayerParams ¶ms);
587 class CV_EXPORTS ChannelsPReLULayer : public ActivationLayer
590 static Ptr<Layer> create(const LayerParams& params);
593 class CV_EXPORTS ELULayer : public ActivationLayer
598 static Ptr<ELULayer> create(const LayerParams ¶ms);
601 class CV_EXPORTS TanHLayer : public ActivationLayer
604 static Ptr<TanHLayer> create(const LayerParams ¶ms);
607 class CV_EXPORTS SwishLayer : public ActivationLayer
610 static Ptr<SwishLayer> create(const LayerParams ¶ms);
613 class CV_EXPORTS MishLayer : public ActivationLayer
616 static Ptr<MishLayer> create(const LayerParams ¶ms);
619 class CV_EXPORTS SigmoidLayer : public ActivationLayer
622 static Ptr<SigmoidLayer> create(const LayerParams ¶ms);
625 class CV_EXPORTS BNLLLayer : public ActivationLayer
628 static Ptr<BNLLLayer> create(const LayerParams ¶ms);
631 class CV_EXPORTS AbsLayer : public ActivationLayer
634 static Ptr<AbsLayer> create(const LayerParams ¶ms);
637 class CV_EXPORTS PowerLayer : public ActivationLayer
640 float power, scale, shift;
642 static Ptr<PowerLayer> create(const LayerParams ¶ms);
645 class CV_EXPORTS ExpLayer : public ActivationLayer
648 float base, scale, shift;
650 static Ptr<ExpLayer> create(const LayerParams ¶ms);
653 class CV_EXPORTS CeilLayer : public ActivationLayer
656 static Ptr<CeilLayer> create(const LayerParams ¶ms);
659 class CV_EXPORTS FloorLayer : public ActivationLayer
662 static Ptr<FloorLayer> create(const LayerParams ¶ms);
665 class CV_EXPORTS LogLayer : public ActivationLayer
668 static Ptr<LogLayer> create(const LayerParams ¶ms);
671 class CV_EXPORTS RoundLayer : public ActivationLayer
674 static Ptr<RoundLayer> create(const LayerParams ¶ms);
677 class CV_EXPORTS SqrtLayer : public ActivationLayer
680 static Ptr<SqrtLayer> create(const LayerParams ¶ms);
683 class CV_EXPORTS NotLayer : public ActivationLayer
686 static Ptr<NotLayer> create(const LayerParams ¶ms);
689 class CV_EXPORTS AcosLayer : public ActivationLayer
692 static Ptr<AcosLayer> create(const LayerParams ¶ms);
695 class CV_EXPORTS AcoshLayer : public ActivationLayer
698 static Ptr<AcoshLayer> create(const LayerParams ¶ms);
701 class CV_EXPORTS AsinLayer : public ActivationLayer
704 static Ptr<AsinLayer> create(const LayerParams ¶ms);
707 class CV_EXPORTS AsinhLayer : public ActivationLayer
710 static Ptr<AsinhLayer> create(const LayerParams ¶ms);
713 class CV_EXPORTS AtanLayer : public ActivationLayer
716 static Ptr<AtanLayer> create(const LayerParams ¶ms);
719 class CV_EXPORTS AtanhLayer : public ActivationLayer
722 static Ptr<AtanhLayer> create(const LayerParams ¶ms);
725 class CV_EXPORTS CosLayer : public ActivationLayer
728 static Ptr<CosLayer> create(const LayerParams ¶ms);
731 class CV_EXPORTS CoshLayer : public ActivationLayer
734 static Ptr<CoshLayer> create(const LayerParams ¶ms);
737 class CV_EXPORTS ErfLayer : public ActivationLayer
740 static Ptr<ErfLayer> create(const LayerParams ¶ms);
743 class CV_EXPORTS HardSwishLayer : public ActivationLayer
746 static Ptr<HardSwishLayer> create(const LayerParams ¶ms);
749 class CV_EXPORTS SinLayer : public ActivationLayer
752 static Ptr<SinLayer> create(const LayerParams ¶ms);
755 class CV_EXPORTS SinhLayer : public ActivationLayer
758 static Ptr<SinhLayer> create(const LayerParams ¶ms);
761 class CV_EXPORTS SoftplusLayer : public ActivationLayer
764 static Ptr<SoftplusLayer> create(const LayerParams ¶ms);
767 class CV_EXPORTS SoftsignLayer : public ActivationLayer
770 static Ptr<SoftsignLayer> create(const LayerParams ¶ms);
773 class CV_EXPORTS TanLayer : public ActivationLayer
776 static Ptr<TanLayer> create(const LayerParams ¶ms);
779 class CV_EXPORTS CeluLayer : public ActivationLayer
784 static Ptr<CeluLayer> create(const LayerParams ¶ms);
787 class CV_EXPORTS HardSigmoidLayer : public ActivationLayer
793 static Ptr<HardSigmoidLayer> create(const LayerParams ¶ms);
796 class CV_EXPORTS SeluLayer : public ActivationLayer
802 static Ptr<SeluLayer> create(const LayerParams ¶ms);
805 class CV_EXPORTS ThresholdedReluLayer : public ActivationLayer
810 static Ptr<ThresholdedReluLayer> create(const LayerParams ¶ms);
813 class CV_EXPORTS ActivationLayerInt8 : public ActivationLayer
816 static Ptr<ActivationLayerInt8> create(const LayerParams ¶ms);
819 class CV_EXPORTS SignLayer : public ActivationLayer
822 static Ptr<SignLayer> create(const LayerParams ¶ms);
825 class CV_EXPORTS ShrinkLayer : public ActivationLayer
830 static Ptr<ShrinkLayer> create(const LayerParams ¶ms);
833 class CV_EXPORTS ReciprocalLayer : public ActivationLayer
836 static Ptr<ReciprocalLayer> create(const LayerParams ¶ms);
839 /* Layers used in semantic segmentation */
841 class CV_EXPORTS CropLayer : public Layer
844 static Ptr<Layer> create(const LayerParams ¶ms);
847 /** @brief Element wise operation on inputs
849 Extra optional parameters:
850 - "operation" as string. Values are "sum" (default), "prod", "max", "div", "min"
851 - "coeff" as float array. Specify weights of inputs for SUM operation
852 - "output_channels_mode" as string. Values are "same" (default, all input must have the same layout), "input_0", "input_0_truncate", "max_input_channels"
854 class CV_EXPORTS EltwiseLayer : public Layer
857 static Ptr<EltwiseLayer> create(const LayerParams ¶ms);
860 class CV_EXPORTS EltwiseLayerInt8 : public Layer
863 static Ptr<EltwiseLayerInt8> create(const LayerParams ¶ms);
866 class CV_EXPORTS NaryEltwiseLayer : public Layer
869 static Ptr<NaryEltwiseLayer> create(const LayerParams ¶ms);
872 class CV_EXPORTS BatchNormLayer : public ActivationLayer
875 bool hasWeights, hasBias;
878 static Ptr<BatchNormLayer> create(const LayerParams ¶ms);
881 class CV_EXPORTS BatchNormLayerInt8 : public BatchNormLayer
884 float input_sc, output_sc;
885 int input_zp, output_zp;
886 static Ptr<BatchNormLayerInt8> create(const LayerParams ¶ms);
889 class CV_EXPORTS MaxUnpoolLayer : public Layer
896 static Ptr<MaxUnpoolLayer> create(const LayerParams ¶ms);
899 class CV_EXPORTS ScaleLayer : public Layer
906 static Ptr<ScaleLayer> create(const LayerParams& params);
909 class CV_EXPORTS ScaleLayerInt8 : public ScaleLayer
914 static Ptr<ScaleLayerInt8> create(const LayerParams ¶ms);
917 class CV_EXPORTS ShiftLayer : public Layer
920 static Ptr<Layer> create(const LayerParams& params);
923 class CV_EXPORTS ShiftLayerInt8 : public Layer
926 static Ptr<Layer> create(const LayerParams& params);
929 class CV_EXPORTS CompareLayer : public Layer
932 static Ptr<Layer> create(const LayerParams& params);
935 class CV_EXPORTS DataAugmentationLayer : public Layer
938 static Ptr<DataAugmentationLayer> create(const LayerParams& params);
941 class CV_EXPORTS CorrelationLayer : public Layer
944 static Ptr<CorrelationLayer> create(const LayerParams& params);
947 class CV_EXPORTS AccumLayer : public Layer
950 static Ptr<AccumLayer> create(const LayerParams& params);
953 class CV_EXPORTS FlowWarpLayer : public Layer
956 static Ptr<FlowWarpLayer> create(const LayerParams& params);
959 class CV_EXPORTS PriorBoxLayer : public Layer
962 static Ptr<PriorBoxLayer> create(const LayerParams& params);
965 class CV_EXPORTS ReorgLayer : public Layer
968 static Ptr<ReorgLayer> create(const LayerParams& params);
971 class CV_EXPORTS RegionLayer : public Layer
976 static Ptr<RegionLayer> create(const LayerParams& params);
980 * @brief Detection output layer.
982 * The layer size is: @f$ (1 \times 1 \times N \times 7) @f$
983 * where N is [keep_top_k] parameter multiplied by batch size. Each row is:
984 * [image_id, label, confidence, xmin, ymin, xmax, ymax]
985 * where image_id is the index of image input in the batch.
987 class CV_EXPORTS DetectionOutputLayer : public Layer
990 static Ptr<DetectionOutputLayer> create(const LayerParams& params);
994 * @brief \f$ L_p \f$ - normalization layer.
995 * @param p Normalization factor. The most common `p = 1` for \f$ L_1 \f$ -
996 * normalization or `p = 2` for \f$ L_2 \f$ - normalization or a custom one.
997 * @param eps Parameter \f$ \epsilon \f$ to prevent a division by zero.
998 * @param across_spatial If true, normalize an input across all non-batch dimensions.
999 * Otherwise normalize an every channel separately.
1003 * norm = \sqrt[p]{\epsilon + \sum_{x, y, c} |src(x, y, c)|^p } \\
1004 * dst(x, y, c) = \frac{ src(x, y, c) }{norm}
1007 * Channel wise normalization:
1009 * norm(c) = \sqrt[p]{\epsilon + \sum_{x, y} |src(x, y, c)|^p } \\
1010 * dst(x, y, c) = \frac{ src(x, y, c) }{norm(c)}
1013 * Where `x, y` - spatial coordinates, `c` - channel.
1015 * An every sample in the batch is normalized separately. Optionally,
1016 * output is scaled by the trained parameters.
1018 class CV_EXPORTS NormalizeBBoxLayer : public Layer
1021 float pnorm, epsilon;
1022 CV_DEPRECATED_EXTERNAL bool acrossSpatial;
1024 static Ptr<NormalizeBBoxLayer> create(const LayerParams& params);
1028 * @brief Resize input 4-dimensional blob by nearest neighbor or bilinear strategy.
1030 * Layer is used to support TensorFlow's resize_nearest_neighbor and resize_bilinear ops.
1032 class CV_EXPORTS ResizeLayer : public Layer
1035 static Ptr<ResizeLayer> create(const LayerParams& params);
1039 * @brief Bilinear resize layer from https://github.com/cdmh/deeplab-public-ver2
1041 * It differs from @ref ResizeLayer in output shape and resize scales computations.
1043 class CV_EXPORTS InterpLayer : public Layer
1046 static Ptr<Layer> create(const LayerParams& params);
1049 class CV_EXPORTS ProposalLayer : public Layer
1052 static Ptr<ProposalLayer> create(const LayerParams& params);
1055 class CV_EXPORTS CropAndResizeLayer : public Layer
1058 static Ptr<Layer> create(const LayerParams& params);
1061 class CV_EXPORTS CumSumLayer : public Layer
1067 static Ptr<CumSumLayer> create(const LayerParams& params);
1070 class CV_EXPORTS ScatterLayer : public Layer
1073 static Ptr<ScatterLayer> create(const LayerParams& params);
1076 class CV_EXPORTS ScatterNDLayer : public Layer
1079 static Ptr<ScatterNDLayer> create(const LayerParams& params);
1082 class CV_EXPORTS TileLayer : public Layer
1085 static Ptr<TileLayer> create(const LayerParams& params);
1090 CV__DNN_INLINE_NS_END