support ReduceLayer without reshape layer.
[platform/upstream/opencv.git] / modules / dnn / include / opencv2 / dnn / all_layers.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
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.
25 //
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.
28 //
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.
39 //
40 //M*/
41
42 #ifndef OPENCV_DNN_DNN_ALL_LAYERS_HPP
43 #define OPENCV_DNN_DNN_ALL_LAYERS_HPP
44 #include <opencv2/dnn.hpp>
45
46 namespace cv {
47 namespace dnn {
48 CV__DNN_INLINE_NS_BEGIN
49 //! @addtogroup dnn
50 //! @{
51
52 /** @defgroup dnnLayerList Partial List of Implemented Layers
53   @{
54   This subsection of dnn module contains information about built-in layers and their descriptions.
55
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()).
59
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:
62   - Convolution
63   - Deconvolution
64   - Pooling
65   - InnerProduct
66   - TanH, ReLU, Sigmoid, BNLL, Power, AbsVal
67   - Softmax
68   - Reshape, Flatten, Slice, Split
69   - LRN
70   - MVN
71   - Dropout (since it does nothing on forward pass -))
72 */
73
74     class CV_EXPORTS BlankLayer : public Layer
75     {
76     public:
77         static Ptr<Layer> create(const LayerParams &params);
78     };
79
80     /**
81      * Constant layer produces the same data blob at an every forward pass.
82      */
83     class CV_EXPORTS ConstLayer : public Layer
84     {
85     public:
86         static Ptr<Layer> create(const LayerParams &params);
87     };
88
89     //! LSTM recurrent layer
90     class CV_EXPORTS LSTMLayer : public Layer
91     {
92     public:
93         /** Creates instance of LSTM layer */
94         static Ptr<LSTMLayer> create(const LayerParams& params);
95
96         /** @deprecated Use LayerParams::blobs instead.
97         @brief Set trained weights for LSTM layer.
98
99         LSTM behavior on each step is defined by current input, previous output, previous cell state and learned weights.
100
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:
103         @f{eqnarray*}{
104         h_t &= o_t \odot tanh(c_t),               \\
105         c_t &= f_t \odot c_{t-1} + i_t \odot g_t, \\
106         @f}
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.
108
109         Gates are computed as follows:
110         @f{eqnarray*}{
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), \\
115         @f}
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$.
118
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$.
123
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$)
127         */
128         CV_DEPRECATED virtual void setWeights(const Mat &Wh, const Mat &Wx, const Mat &b) = 0;
129
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().
133           */
134         virtual void setOutShape(const MatShape &outTailShape = MatShape()) = 0;
135
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.
138           *
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.
141           *
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]`].
144           */
145         CV_DEPRECATED virtual void setUseTimstampsDim(bool use = true) = 0;
146
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.
150          */
151         CV_DEPRECATED virtual void setProduceCellOutput(bool produce = false) = 0;
152
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).
156          *
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, ...]).
159          *
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, ...]).
162         */
163
164         int inputNameToIndex(String inputName) CV_OVERRIDE;
165         int outputNameToIndex(const String& outputName) CV_OVERRIDE;
166     };
167
168     /** @brief GRU recurrent one-layer
169      *
170      * Accepts input sequence and computes the final hidden state for each element in the batch.
171      *
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`
175      *
176      * Depends on the following attributes:
177      * - hidden_size - Number of neurons in the hidden layer
178      * - direction - RNN could be bidirectional or forward
179      *
180      * The final hidden state @f$ h_t @f$ computes by the following formulas:
181      *
182      @f{eqnarray*}{
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)} \\
187      @f}
188      * Where @f$x_t@f$ is current input, @f$h_{(t-1)}@f$ is previous or initial hidden state.
189      *
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$.
192      *
193      * @f$\odot@f$ is per-element multiply operation.
194     */
195     class CV_EXPORTS GRULayer : public Layer
196     {
197     public:
198         /** Creates instance of GRU layer */
199         static Ptr<GRULayer> create(const LayerParams& params);
200     };
201
202     /** @brief Classical recurrent layer
203
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$.
205
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).
208
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.
210
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.
212
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.
214     */
215     class CV_EXPORTS RNNLayer : public Layer
216     {
217     public:
218         /** Creates instance of RNNLayer */
219         static Ptr<RNNLayer> create(const LayerParams& params);
220
221         /** Setups learned weights.
222
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:
224         @f{eqnarray*}{
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),
227         @f}
228
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
234         */
235         virtual void setWeights(const Mat &Wxh, const Mat &bh, const Mat &Whh, const Mat &Who, const Mat &bo) = 0;
236
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.
239          */
240         virtual void setProduceHiddenOutput(bool produce = false) = 0;
241
242     };
243
244     class CV_EXPORTS BaseConvolutionLayer : public Layer
245     {
246     public:
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;
251         String padMode;
252         int numOutput;
253     };
254
255     class CV_EXPORTS ConvolutionLayer : public BaseConvolutionLayer
256     {
257     public:
258         static Ptr<BaseConvolutionLayer> create(const LayerParams& params);
259     };
260
261     class CV_EXPORTS ConvolutionLayerInt8 : public BaseConvolutionLayer
262     {
263     public:
264         int input_zp, output_zp;
265         float input_sc, output_sc;
266
267         // quantization type flag. The perChannel default is true, that means it contains the parameters
268         // of per-Channel quantization. Otherwise, that means this layer contains per-Tensor quantized parameters.
269         bool per_channel;
270         static Ptr<BaseConvolutionLayer> create(const LayerParams& params);
271     };
272
273     class CV_EXPORTS DeconvolutionLayer : public BaseConvolutionLayer
274     {
275     public:
276         static Ptr<BaseConvolutionLayer> create(const LayerParams& params);
277     };
278
279     class CV_EXPORTS LRNLayer : public Layer
280     {
281     public:
282         int type;
283
284         int size;
285         float alpha, beta, bias;
286         bool normBySize;
287
288         static Ptr<LRNLayer> create(const LayerParams& params);
289     };
290
291
292     /** @brief ArgMax/ArgMin layer
293      * @note returns indices as floats, which means the supported range is [-2^24; 2^24]
294      */
295     class CV_EXPORTS ArgLayer : public Layer
296     {
297     public:
298         static Ptr<ArgLayer> create(const LayerParams& params);
299     };
300
301     class CV_EXPORTS PoolingLayer : public Layer
302     {
303     public:
304         int type;
305         std::vector<size_t> kernel_size, strides;
306         std::vector<size_t> pads_begin, pads_end;
307         bool globalPooling; //!< Flag is true if at least one of the axes is global pooled.
308         std::vector<bool> isGlobalPooling;
309         bool computeMaxIdx;
310         String padMode;
311         bool ceilMode;
312         // If true for average pooling with padding, divide an every output region
313         // by a whole kernel area. Otherwise exclude zero padded values and divide
314         // by number of real values.
315         bool avePoolPaddedArea;
316         // ROIPooling parameters.
317         Size pooledSize;
318         float spatialScale;
319         // PSROIPooling parameters.
320         int psRoiOutChannels;
321
322         static Ptr<PoolingLayer> create(const LayerParams& params);
323     };
324
325     class CV_EXPORTS PoolingLayerInt8 : public PoolingLayer
326     {
327     public:
328         int input_zp, output_zp;
329         float input_sc, output_sc;
330         static Ptr<PoolingLayerInt8> create(const LayerParams& params);
331     };
332
333     class CV_EXPORTS ReduceLayer : public Layer
334     {
335     public:
336         int reduceType;
337         // reduceDims contains the dimensions that need to be reduced, targetDims is the target output dimension.
338         std::vector<size_t> reduceDims, targetDims;
339         static Ptr<ReduceLayer> create(const LayerParams& params);
340     };
341
342     class CV_EXPORTS ReduceLayerInt8 : public ReduceLayer
343     {
344     public:
345         static Ptr<ReduceLayerInt8> create(const LayerParams& params);
346     };
347
348     class CV_EXPORTS SoftmaxLayer : public Layer
349     {
350     public:
351         bool logSoftMax;
352
353         static Ptr<SoftmaxLayer> create(const LayerParams& params);
354     };
355
356     class CV_EXPORTS SoftmaxLayerInt8 : public SoftmaxLayer
357     {
358     public:
359         float output_sc;
360         int output_zp;
361         static Ptr<SoftmaxLayerInt8> create(const LayerParams& params);
362     };
363
364     class CV_EXPORTS InnerProductLayer : public Layer
365     {
366     public:
367         int axis;
368         static Ptr<InnerProductLayer> create(const LayerParams& params);
369     };
370
371     class CV_EXPORTS InnerProductLayerInt8 : public InnerProductLayer
372     {
373     public:
374         int input_zp, output_zp;
375         float input_sc, output_sc;
376
377         // quantization type flag. The perChannel default is true, that means it contains the parameters
378         // of per-Channel quantization. Otherwise, that means this layer contains per-Tensor quantized parameters.
379         bool per_channel;
380         static Ptr<InnerProductLayerInt8> create(const LayerParams& params);
381     };
382
383     class CV_EXPORTS MVNLayer : public Layer
384     {
385     public:
386         float eps;
387         bool normVariance, acrossChannels;
388
389         static Ptr<MVNLayer> create(const LayerParams& params);
390     };
391
392     /* Reshaping */
393
394     class CV_EXPORTS ReshapeLayer : public Layer
395     {
396     public:
397         MatShape newShapeDesc;
398         Range newShapeRange;
399
400         static Ptr<ReshapeLayer> create(const LayerParams& params);
401     };
402
403     class CV_EXPORTS FlattenLayer : public Layer
404     {
405     public:
406         static Ptr<FlattenLayer> create(const LayerParams &params);
407     };
408
409     class CV_EXPORTS QuantizeLayer : public Layer
410     {
411     public:
412         float scale;
413         int zeropoint;
414         static Ptr<QuantizeLayer> create(const LayerParams &params);
415     };
416
417     class CV_EXPORTS DequantizeLayer : public Layer
418     {
419     public:
420         float scale;
421         int zeropoint;
422         static Ptr<DequantizeLayer> create(const LayerParams &params);
423     };
424
425     class CV_EXPORTS RequantizeLayer : public Layer
426     {
427     public:
428         float scale, shift;
429         static Ptr<RequantizeLayer> create(const LayerParams &params);
430     };
431
432     class CV_EXPORTS ConcatLayer : public Layer
433     {
434     public:
435         int axis;
436         /**
437          * @brief Add zero padding in case of concatenation of blobs with different
438          * spatial sizes.
439          *
440          * Details: https://github.com/torch/nn/blob/master/doc/containers.md#depthconcat
441          */
442         bool padding;
443         int paddingValue;
444
445         static Ptr<ConcatLayer> create(const LayerParams &params);
446     };
447
448     class CV_EXPORTS SplitLayer : public Layer
449     {
450     public:
451         int outputsCount; //!< Number of copies that will be produced (is ignored when negative).
452
453         static Ptr<SplitLayer> create(const LayerParams &params);
454     };
455
456     /**
457      * Slice layer has several modes:
458      * 1. Caffe mode
459      * @param[in] axis Axis of split operation
460      * @param[in] slice_point Array of split points
461      *
462      * Number of output blobs equals to number of split points plus one. The
463      * first blob is a slice on input from 0 to @p slice_point[0] - 1 by @p axis,
464      * the second output blob is a slice of input from @p slice_point[0] to
465      * @p slice_point[1] - 1 by @p axis and the last output blob is a slice of
466      * input from @p slice_point[-1] up to the end of @p axis size.
467      *
468      * 2. TensorFlow mode
469      * @param begin Vector of start indices
470      * @param size Vector of sizes
471      *
472      * More convenient numpy-like slice. One and only output blob
473      * is a slice `input[begin[0]:begin[0]+size[0], begin[1]:begin[1]+size[1], ...]`
474      *
475      * 3. Torch mode
476      * @param axis Axis of split operation
477      *
478      * Split input blob on the equal parts by @p axis.
479      */
480     class CV_EXPORTS SliceLayer : public Layer
481     {
482     public:
483         /**
484          * @brief Vector of slice ranges.
485          *
486          * The first dimension equals number of output blobs.
487          * Inner vector has slice ranges for the first number of input dimensions.
488          */
489         std::vector<std::vector<Range> > sliceRanges;
490         std::vector<std::vector<int> > sliceSteps;
491         int axis;
492         int num_split;
493
494         static Ptr<SliceLayer> create(const LayerParams &params);
495     };
496
497     class CV_EXPORTS PermuteLayer : public Layer
498     {
499     public:
500         static Ptr<PermuteLayer> create(const LayerParams& params);
501     };
502
503     /**
504      * Permute channels of 4-dimensional input blob.
505      * @param group Number of groups to split input channels and pick in turns
506      *              into output blob.
507      *
508      * \f[ groupSize = \frac{number\ of\ channels}{group} \f]
509      * \f[ output(n, c, h, w) = input(n, groupSize \times (c \% group) + \lfloor \frac{c}{group} \rfloor, h, w) \f]
510      * Read more at https://arxiv.org/pdf/1707.01083.pdf
511      */
512     class CV_EXPORTS ShuffleChannelLayer : public Layer
513     {
514     public:
515         static Ptr<Layer> create(const LayerParams& params);
516
517         int group;
518     };
519
520     /**
521      * @brief Adds extra values for specific axes.
522      * @param paddings Vector of paddings in format
523      *                 @code
524      *                 [ pad_before, pad_after,  // [0]th dimension
525      *                   pad_before, pad_after,  // [1]st dimension
526      *                   ...
527      *                   pad_before, pad_after ] // [n]th dimension
528      *                 @endcode
529      *                 that represents number of padded values at every dimension
530      *                 starting from the first one. The rest of dimensions won't
531      *                 be padded.
532      * @param value Value to be padded. Defaults to zero.
533      * @param type Padding type: 'constant', 'reflect'
534      * @param input_dims Torch's parameter. If @p input_dims is not equal to the
535      *                   actual input dimensionality then the `[0]th` dimension
536      *                   is considered as a batch dimension and @p paddings are shifted
537      *                   to a one dimension. Defaults to `-1` that means padding
538      *                   corresponding to @p paddings.
539      */
540     class CV_EXPORTS PaddingLayer : public Layer
541     {
542     public:
543         static Ptr<PaddingLayer> create(const LayerParams& params);
544     };
545
546     /* Activations */
547     class CV_EXPORTS ActivationLayer : public Layer
548     {
549     public:
550         virtual void forwardSlice(const float* src, float* dst, int len,
551                                   size_t outPlaneSize, int cn0, int cn1) const {};
552         virtual void forwardSlice(const int* src, const int* lut, int* dst, int len,
553                                   size_t outPlaneSize, int cn0, int cn1) const {};
554         virtual void forwardSlice(const int8_t* src, const int8_t* lut, int8_t* dst, int len,
555                                   size_t outPlaneSize, int cn0, int cn1) const {};
556     };
557
558     class CV_EXPORTS ReLULayer : public ActivationLayer
559     {
560     public:
561         float negativeSlope;
562
563         static Ptr<ReLULayer> create(const LayerParams &params);
564     };
565
566     class CV_EXPORTS ReLU6Layer : public ActivationLayer
567     {
568     public:
569         float minValue, maxValue;
570
571         static Ptr<ReLU6Layer> create(const LayerParams &params);
572     };
573
574     class CV_EXPORTS ChannelsPReLULayer : public ActivationLayer
575     {
576     public:
577         static Ptr<Layer> create(const LayerParams& params);
578     };
579
580     class CV_EXPORTS ELULayer : public ActivationLayer
581     {
582     public:
583         float alpha;
584
585         static Ptr<ELULayer> create(const LayerParams &params);
586     };
587
588     class CV_EXPORTS TanHLayer : public ActivationLayer
589     {
590     public:
591         static Ptr<TanHLayer> create(const LayerParams &params);
592     };
593
594     class CV_EXPORTS SwishLayer : public ActivationLayer
595     {
596     public:
597         static Ptr<SwishLayer> create(const LayerParams &params);
598     };
599
600     class CV_EXPORTS MishLayer : public ActivationLayer
601     {
602     public:
603         static Ptr<MishLayer> create(const LayerParams &params);
604     };
605
606     class CV_EXPORTS SigmoidLayer : public ActivationLayer
607     {
608     public:
609         static Ptr<SigmoidLayer> create(const LayerParams &params);
610     };
611
612     class CV_EXPORTS BNLLLayer : public ActivationLayer
613     {
614     public:
615         static Ptr<BNLLLayer> create(const LayerParams &params);
616     };
617
618     class CV_EXPORTS AbsLayer : public ActivationLayer
619     {
620     public:
621         static Ptr<AbsLayer> create(const LayerParams &params);
622     };
623
624     class CV_EXPORTS PowerLayer : public ActivationLayer
625     {
626     public:
627         float power, scale, shift;
628
629         static Ptr<PowerLayer> create(const LayerParams &params);
630     };
631
632     class CV_EXPORTS ExpLayer : public ActivationLayer
633     {
634     public:
635         float base, scale, shift;
636
637         static Ptr<ExpLayer> create(const LayerParams &params);
638     };
639
640     class CV_EXPORTS CeilLayer : public ActivationLayer
641     {
642     public:
643         static Ptr<CeilLayer> create(const LayerParams &params);
644     };
645
646     class CV_EXPORTS FloorLayer : public ActivationLayer
647     {
648     public:
649         static Ptr<FloorLayer> create(const LayerParams &params);
650     };
651
652     class CV_EXPORTS LogLayer : public ActivationLayer
653     {
654     public:
655         static Ptr<LogLayer> create(const LayerParams &params);
656     };
657
658     class CV_EXPORTS RoundLayer : public ActivationLayer
659     {
660     public:
661         static Ptr<RoundLayer> create(const LayerParams &params);
662     };
663
664     class CV_EXPORTS SqrtLayer : public ActivationLayer
665     {
666     public:
667         static Ptr<SqrtLayer> create(const LayerParams &params);
668     };
669
670     class CV_EXPORTS NotLayer : public ActivationLayer
671     {
672     public:
673         static Ptr<NotLayer> create(const LayerParams &params);
674     };
675
676     class CV_EXPORTS AcosLayer : public ActivationLayer
677     {
678     public:
679         static Ptr<AcosLayer> create(const LayerParams &params);
680     };
681
682     class CV_EXPORTS AcoshLayer : public ActivationLayer
683     {
684     public:
685         static Ptr<AcoshLayer> create(const LayerParams &params);
686     };
687
688     class CV_EXPORTS AsinLayer : public ActivationLayer
689     {
690     public:
691         static Ptr<AsinLayer> create(const LayerParams &params);
692     };
693
694     class CV_EXPORTS AsinhLayer : public ActivationLayer
695     {
696     public:
697         static Ptr<AsinhLayer> create(const LayerParams &params);
698     };
699
700     class CV_EXPORTS AtanLayer : public ActivationLayer
701     {
702     public:
703         static Ptr<AtanLayer> create(const LayerParams &params);
704     };
705
706     class CV_EXPORTS AtanhLayer : public ActivationLayer
707     {
708     public:
709         static Ptr<AtanhLayer> create(const LayerParams &params);
710     };
711
712     class CV_EXPORTS CosLayer : public ActivationLayer
713     {
714     public:
715         static Ptr<CosLayer> create(const LayerParams &params);
716     };
717
718     class CV_EXPORTS CoshLayer : public ActivationLayer
719     {
720     public:
721         static Ptr<CoshLayer> create(const LayerParams &params);
722     };
723
724     class CV_EXPORTS ErfLayer : public ActivationLayer
725     {
726     public:
727         static Ptr<ErfLayer> create(const LayerParams &params);
728     };
729
730     class CV_EXPORTS HardSwishLayer : public ActivationLayer
731     {
732     public:
733         static Ptr<HardSwishLayer> create(const LayerParams &params);
734     };
735
736     class CV_EXPORTS SinLayer : public ActivationLayer
737     {
738     public:
739         static Ptr<SinLayer> create(const LayerParams &params);
740     };
741
742     class CV_EXPORTS SinhLayer : public ActivationLayer
743     {
744     public:
745         static Ptr<SinhLayer> create(const LayerParams &params);
746     };
747
748     class CV_EXPORTS SoftplusLayer : public ActivationLayer
749     {
750     public:
751         static Ptr<SoftplusLayer> create(const LayerParams &params);
752     };
753
754     class CV_EXPORTS SoftsignLayer : public ActivationLayer
755     {
756     public:
757         static Ptr<SoftsignLayer> create(const LayerParams &params);
758     };
759
760     class CV_EXPORTS TanLayer : public ActivationLayer
761     {
762     public:
763         static Ptr<TanLayer> create(const LayerParams &params);
764     };
765
766     class CV_EXPORTS CeluLayer : public ActivationLayer
767     {
768     public:
769         float alpha;
770
771         static Ptr<CeluLayer> create(const LayerParams &params);
772     };
773
774     class CV_EXPORTS HardSigmoidLayer : public ActivationLayer
775     {
776     public:
777         float alpha;
778         float beta;
779
780         static Ptr<HardSigmoidLayer> create(const LayerParams &params);
781     };
782
783     class CV_EXPORTS SeluLayer : public ActivationLayer
784     {
785     public:
786         float alpha;
787         float gamma;
788
789         static Ptr<SeluLayer> create(const LayerParams &params);
790     };
791
792     class CV_EXPORTS ThresholdedReluLayer : public ActivationLayer
793     {
794     public:
795         float alpha;
796
797         static Ptr<ThresholdedReluLayer> create(const LayerParams &params);
798     };
799
800     class CV_EXPORTS ActivationLayerInt8 : public ActivationLayer
801     {
802     public:
803         static Ptr<ActivationLayerInt8> create(const LayerParams &params);
804     };
805
806     class CV_EXPORTS SignLayer : public ActivationLayer
807     {
808     public:
809         static Ptr<SignLayer> create(const LayerParams &params);
810     };
811
812     class CV_EXPORTS ShrinkLayer : public ActivationLayer
813     {
814     public:
815         float bias;
816         float lambd;
817         static Ptr<ShrinkLayer> create(const LayerParams &params);
818     };
819
820     class CV_EXPORTS ReciprocalLayer : public ActivationLayer
821     {
822     public:
823         static Ptr<ReciprocalLayer> create(const LayerParams &params);
824     };
825
826     /* Layers used in semantic segmentation */
827
828     class CV_EXPORTS CropLayer : public Layer
829     {
830     public:
831         static Ptr<Layer> create(const LayerParams &params);
832     };
833
834     /** @brief Element wise operation on inputs
835
836     Extra optional parameters:
837     - "operation" as string. Values are "sum" (default), "prod", "max", "div", "min"
838     - "coeff" as float array. Specify weights of inputs for SUM operation
839     - "output_channels_mode" as string. Values are "same" (default, all input must have the same layout), "input_0", "input_0_truncate", "max_input_channels"
840     */
841     class CV_EXPORTS EltwiseLayer : public Layer
842     {
843     public:
844         static Ptr<EltwiseLayer> create(const LayerParams &params);
845     };
846
847     class CV_EXPORTS EltwiseLayerInt8 : public Layer
848     {
849     public:
850         static Ptr<EltwiseLayerInt8> create(const LayerParams &params);
851     };
852
853     class CV_EXPORTS BatchNormLayer : public ActivationLayer
854     {
855     public:
856         bool hasWeights, hasBias;
857         float epsilon;
858
859         static Ptr<BatchNormLayer> create(const LayerParams &params);
860     };
861
862     class CV_EXPORTS BatchNormLayerInt8 : public BatchNormLayer
863     {
864     public:
865         float input_sc, output_sc;
866         int input_zp, output_zp;
867         static Ptr<BatchNormLayerInt8> create(const LayerParams &params);
868     };
869
870     class CV_EXPORTS MaxUnpoolLayer : public Layer
871     {
872     public:
873         Size poolKernel;
874         Size poolPad;
875         Size poolStride;
876
877         static Ptr<MaxUnpoolLayer> create(const LayerParams &params);
878     };
879
880     class CV_EXPORTS ScaleLayer : public Layer
881     {
882     public:
883         bool hasBias;
884         int axis;
885         String mode;
886
887         static Ptr<ScaleLayer> create(const LayerParams& params);
888     };
889
890     class CV_EXPORTS ScaleLayerInt8 : public ScaleLayer
891     {
892     public:
893         float output_sc;
894         int output_zp;
895         static Ptr<ScaleLayerInt8> create(const LayerParams &params);
896     };
897
898     class CV_EXPORTS ShiftLayer : public Layer
899     {
900     public:
901         static Ptr<Layer> create(const LayerParams& params);
902     };
903
904     class CV_EXPORTS ShiftLayerInt8 : public Layer
905     {
906     public:
907         static Ptr<Layer> create(const LayerParams& params);
908     };
909
910     class CV_EXPORTS CompareLayer : public Layer
911     {
912     public:
913         static Ptr<Layer> create(const LayerParams& params);
914     };
915
916     class CV_EXPORTS DataAugmentationLayer : public Layer
917     {
918     public:
919         static Ptr<DataAugmentationLayer> create(const LayerParams& params);
920     };
921
922     class CV_EXPORTS CorrelationLayer : public Layer
923     {
924     public:
925         static Ptr<CorrelationLayer> create(const LayerParams& params);
926     };
927
928     class CV_EXPORTS AccumLayer : public Layer
929     {
930     public:
931         static Ptr<AccumLayer> create(const LayerParams& params);
932     };
933
934     class CV_EXPORTS FlowWarpLayer : public Layer
935     {
936     public:
937         static Ptr<FlowWarpLayer> create(const LayerParams& params);
938     };
939
940     class CV_EXPORTS PriorBoxLayer : public Layer
941     {
942     public:
943         static Ptr<PriorBoxLayer> create(const LayerParams& params);
944     };
945
946     class CV_EXPORTS ReorgLayer : public Layer
947     {
948     public:
949         static Ptr<ReorgLayer> create(const LayerParams& params);
950     };
951
952     class CV_EXPORTS RegionLayer : public Layer
953     {
954     public:
955         float nmsThreshold;
956
957         static Ptr<RegionLayer> create(const LayerParams& params);
958     };
959
960     /**
961      * @brief Detection output layer.
962      *
963      * The layer size is: @f$ (1 \times 1 \times N \times 7) @f$
964      *    where N is [keep_top_k] parameter multiplied by batch size. Each row is:
965      *    [image_id, label, confidence, xmin, ymin, xmax, ymax]
966      *    where image_id is the index of image input in the batch.
967      */
968     class CV_EXPORTS DetectionOutputLayer : public Layer
969     {
970     public:
971         static Ptr<DetectionOutputLayer> create(const LayerParams& params);
972     };
973
974     /**
975      * @brief \f$ L_p \f$ - normalization layer.
976      * @param p Normalization factor. The most common `p = 1` for \f$ L_1 \f$ -
977      *          normalization or `p = 2` for \f$ L_2 \f$ - normalization or a custom one.
978      * @param eps Parameter \f$ \epsilon \f$ to prevent a division by zero.
979      * @param across_spatial If true, normalize an input across all non-batch dimensions.
980      *                       Otherwise normalize an every channel separately.
981      *
982      * Across spatial:
983      * @f[
984      * norm = \sqrt[p]{\epsilon + \sum_{x, y, c} |src(x, y, c)|^p } \\
985      * dst(x, y, c) = \frac{ src(x, y, c) }{norm}
986      * @f]
987      *
988      * Channel wise normalization:
989      * @f[
990      * norm(c) = \sqrt[p]{\epsilon + \sum_{x, y} |src(x, y, c)|^p } \\
991      * dst(x, y, c) = \frac{ src(x, y, c) }{norm(c)}
992      * @f]
993      *
994      * Where `x, y` - spatial coordinates, `c` - channel.
995      *
996      * An every sample in the batch is normalized separately. Optionally,
997      * output is scaled by the trained parameters.
998      */
999     class CV_EXPORTS NormalizeBBoxLayer : public Layer
1000     {
1001     public:
1002         float pnorm, epsilon;
1003         CV_DEPRECATED_EXTERNAL bool acrossSpatial;
1004
1005         static Ptr<NormalizeBBoxLayer> create(const LayerParams& params);
1006     };
1007
1008     /**
1009      * @brief Resize input 4-dimensional blob by nearest neighbor or bilinear strategy.
1010      *
1011      * Layer is used to support TensorFlow's resize_nearest_neighbor and resize_bilinear ops.
1012      */
1013     class CV_EXPORTS ResizeLayer : public Layer
1014     {
1015     public:
1016         static Ptr<ResizeLayer> create(const LayerParams& params);
1017     };
1018
1019     /**
1020      * @brief Bilinear resize layer from https://github.com/cdmh/deeplab-public-ver2
1021      *
1022      * It differs from @ref ResizeLayer in output shape and resize scales computations.
1023      */
1024     class CV_EXPORTS InterpLayer : public Layer
1025     {
1026     public:
1027         static Ptr<Layer> create(const LayerParams& params);
1028     };
1029
1030     class CV_EXPORTS ProposalLayer : public Layer
1031     {
1032     public:
1033         static Ptr<ProposalLayer> create(const LayerParams& params);
1034     };
1035
1036     class CV_EXPORTS CropAndResizeLayer : public Layer
1037     {
1038     public:
1039         static Ptr<Layer> create(const LayerParams& params);
1040     };
1041
1042     class CV_EXPORTS CumSumLayer : public Layer
1043     {
1044     public:
1045         int exclusive;
1046         int reverse;
1047
1048         static Ptr<CumSumLayer> create(const LayerParams& params);
1049     };
1050
1051 //! @}
1052 //! @}
1053 CV__DNN_INLINE_NS_END
1054 }
1055 }
1056 #endif