all_layers.hpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  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. #ifndef OPENCV_DNN_DNN_ALL_LAYERS_HPP
  42. #define OPENCV_DNN_DNN_ALL_LAYERS_HPP
  43. #include <opencv2/dnn.hpp>
  44. namespace cv {
  45. namespace dnn {
  46. CV__DNN_EXPERIMENTAL_NS_BEGIN
  47. //! @addtogroup dnn
  48. //! @{
  49. /** @defgroup dnnLayerList Partial List of Implemented Layers
  50. @{
  51. This subsection of dnn module contains information about built-in layers and their descriptions.
  52. Classes listed here, in fact, provides C++ API for creating instances of built-in layers.
  53. 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.
  54. 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()).
  55. Built-in layers partially reproduce functionality of corresponding Caffe and Torch7 layers.
  56. In particular, the following layers and Caffe importer were tested to reproduce <a href="http://caffe.berkeleyvision.org/tutorial/layers.html">Caffe</a> functionality:
  57. - Convolution
  58. - Deconvolution
  59. - Pooling
  60. - InnerProduct
  61. - TanH, ReLU, Sigmoid, BNLL, Power, AbsVal
  62. - Softmax
  63. - Reshape, Flatten, Slice, Split
  64. - LRN
  65. - MVN
  66. - Dropout (since it does nothing on forward pass -))
  67. */
  68. class CV_EXPORTS BlankLayer : public Layer
  69. {
  70. public:
  71. static Ptr<Layer> create(const LayerParams &params);
  72. };
  73. /**
  74. * Constant layer produces the same data blob at an every forward pass.
  75. */
  76. class CV_EXPORTS ConstLayer : public Layer
  77. {
  78. public:
  79. static Ptr<Layer> create(const LayerParams &params);
  80. };
  81. //! LSTM recurrent layer
  82. class CV_EXPORTS LSTMLayer : public Layer
  83. {
  84. public:
  85. /** Creates instance of LSTM layer */
  86. static Ptr<LSTMLayer> create(const LayerParams& params);
  87. /** @deprecated Use LayerParams::blobs instead.
  88. @brief Set trained weights for LSTM layer.
  89. LSTM behavior on each step is defined by current input, previous output, previous cell state and learned weights.
  90. Let @f$x_t@f$ be current input, @f$h_t@f$ be current output, @f$c_t@f$ be current state.
  91. Than current output and current cell state is computed as follows:
  92. @f{eqnarray*}{
  93. h_t &= o_t \odot tanh(c_t), \\
  94. c_t &= f_t \odot c_{t-1} + i_t \odot g_t, \\
  95. @f}
  96. 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.
  97. Gates are computed as follows:
  98. @f{eqnarray*}{
  99. i_t &= sigmoid&(W_{xi} x_t + W_{hi} h_{t-1} + b_i), \\
  100. f_t &= sigmoid&(W_{xf} x_t + W_{hf} h_{t-1} + b_f), \\
  101. o_t &= sigmoid&(W_{xo} x_t + W_{ho} h_{t-1} + b_o), \\
  102. g_t &= tanh &(W_{xg} x_t + W_{hg} h_{t-1} + b_g), \\
  103. @f}
  104. where @f$W_{x?}@f$, @f$W_{h?}@f$ and @f$b_{?}@f$ are learned weights represented as matrices:
  105. @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$.
  106. For simplicity and performance purposes we use @f$ W_x = [W_{xi}; W_{xf}; W_{xo}, W_{xg}] @f$
  107. (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$.
  108. The same for @f$ W_h = [W_{hi}; W_{hf}; W_{ho}, W_{hg}], W_h \in R^{4N_h \times N_h} @f$
  109. and for @f$ b = [b_i; b_f, b_o, b_g]@f$, @f$b \in R^{4N_h} @f$.
  110. @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$)
  111. @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$)
  112. @param b is bias vector (i.e. according to above mentioned notation is @f$ b @f$)
  113. */
  114. CV_DEPRECATED virtual void setWeights(const Mat &Wh, const Mat &Wx, const Mat &b) = 0;
  115. /** @brief Specifies shape of output blob which will be [[`T`], `N`] + @p outTailShape.
  116. * @details If this parameter is empty or unset then @p outTailShape = [`Wh`.size(0)] will be used,
  117. * where `Wh` is parameter from setWeights().
  118. */
  119. virtual void setOutShape(const MatShape &outTailShape = MatShape()) = 0;
  120. /** @deprecated Use flag `produce_cell_output` in LayerParams.
  121. * @brief Specifies either interpret first dimension of input blob as timestamp dimension either as sample.
  122. *
  123. * 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.
  124. * In this case each forward() call will iterate through `T` timestamps and update layer's state `T` times.
  125. *
  126. * If flag is set to false then shape of input blob will be interpreted as [`N`, `[data dims]`].
  127. * In this case each forward() call will make one iteration and produce one timestamp with shape [`N`, `[out dims]`].
  128. */
  129. CV_DEPRECATED virtual void setUseTimstampsDim(bool use = true) = 0;
  130. /** @deprecated Use flag `use_timestamp_dim` in LayerParams.
  131. * @brief If this flag is set to true then layer will produce @f$ c_t @f$ as second output.
  132. * @details Shape of the second output is the same as first output.
  133. */
  134. CV_DEPRECATED virtual void setProduceCellOutput(bool produce = false) = 0;
  135. /* 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$).
  136. * @param input should contain packed values @f$x_t@f$
  137. * @param output contains computed outputs: @f$h_t@f$ (and @f$c_t@f$ if setProduceCellOutput() flag was set to true).
  138. *
  139. * If setUseTimstampsDim() is set to true then @p input[0] should has at least two dimensions with the following shape: [`T`, `N`, `[data dims]`],
  140. * 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, ...]).
  141. *
  142. * 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.
  143. * (i.e. @f$ x_{t}^{stream} @f$ is stored inside @p input[0][stream, ...]).
  144. */
  145. int inputNameToIndex(String inputName) CV_OVERRIDE;
  146. int outputNameToIndex(const String& outputName) CV_OVERRIDE;
  147. };
  148. /** @brief Classical recurrent layer
  149. 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$.
  150. - input: should contain packed input @f$x_t@f$.
  151. - output: should contain output @f$o_t@f$ (and @f$h_t@f$ if setProduceHiddenOutput() is set to true).
  152. 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.
  153. 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.
  154. 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.
  155. */
  156. class CV_EXPORTS RNNLayer : public Layer
  157. {
  158. public:
  159. /** Creates instance of RNNLayer */
  160. static Ptr<RNNLayer> create(const LayerParams& params);
  161. /** Setups learned weights.
  162. 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:
  163. @f{eqnarray*}{
  164. h_t &= tanh&(W_{hh} h_{t-1} + W_{xh} x_t + b_h), \\
  165. o_t &= tanh&(W_{ho} h_t + b_o),
  166. @f}
  167. @param Wxh is @f$ W_{xh} @f$ matrix
  168. @param bh is @f$ b_{h} @f$ vector
  169. @param Whh is @f$ W_{hh} @f$ matrix
  170. @param Who is @f$ W_{xo} @f$ matrix
  171. @param bo is @f$ b_{o} @f$ vector
  172. */
  173. virtual void setWeights(const Mat &Wxh, const Mat &bh, const Mat &Whh, const Mat &Who, const Mat &bo) = 0;
  174. /** @brief If this flag is set to true then layer will produce @f$ h_t @f$ as second output.
  175. * @details Shape of the second output is the same as first output.
  176. */
  177. virtual void setProduceHiddenOutput(bool produce = false) = 0;
  178. };
  179. class CV_EXPORTS BaseConvolutionLayer : public Layer
  180. {
  181. public:
  182. CV_DEPRECATED_EXTERNAL Size kernel, stride, pad, dilation, adjustPad;
  183. std::vector<size_t> adjust_pads;
  184. std::vector<size_t> kernel_size, strides, dilations;
  185. std::vector<size_t> pads_begin, pads_end;
  186. String padMode;
  187. int numOutput;
  188. };
  189. class CV_EXPORTS ConvolutionLayer : public BaseConvolutionLayer
  190. {
  191. public:
  192. static Ptr<BaseConvolutionLayer> create(const LayerParams& params);
  193. };
  194. class CV_EXPORTS DeconvolutionLayer : public BaseConvolutionLayer
  195. {
  196. public:
  197. static Ptr<BaseConvolutionLayer> create(const LayerParams& params);
  198. };
  199. class CV_EXPORTS LRNLayer : public Layer
  200. {
  201. public:
  202. int type;
  203. int size;
  204. float alpha, beta, bias;
  205. bool normBySize;
  206. static Ptr<LRNLayer> create(const LayerParams& params);
  207. };
  208. class CV_EXPORTS PoolingLayer : public Layer
  209. {
  210. public:
  211. int type;
  212. std::vector<size_t> kernel_size, strides;
  213. std::vector<size_t> pads_begin, pads_end;
  214. bool globalPooling; //!< Flag is true if at least one of the axes is global pooled.
  215. std::vector<bool> isGlobalPooling;
  216. bool computeMaxIdx;
  217. String padMode;
  218. bool ceilMode;
  219. // If true for average pooling with padding, divide an every output region
  220. // by a whole kernel area. Otherwise exclude zero padded values and divide
  221. // by number of real values.
  222. bool avePoolPaddedArea;
  223. // ROIPooling parameters.
  224. Size pooledSize;
  225. float spatialScale;
  226. // PSROIPooling parameters.
  227. int psRoiOutChannels;
  228. static Ptr<PoolingLayer> create(const LayerParams& params);
  229. };
  230. class CV_EXPORTS SoftmaxLayer : public Layer
  231. {
  232. public:
  233. bool logSoftMax;
  234. static Ptr<SoftmaxLayer> create(const LayerParams& params);
  235. };
  236. class CV_EXPORTS InnerProductLayer : public Layer
  237. {
  238. public:
  239. int axis;
  240. static Ptr<InnerProductLayer> create(const LayerParams& params);
  241. };
  242. class CV_EXPORTS MVNLayer : public Layer
  243. {
  244. public:
  245. float eps;
  246. bool normVariance, acrossChannels;
  247. static Ptr<MVNLayer> create(const LayerParams& params);
  248. };
  249. /* Reshaping */
  250. class CV_EXPORTS ReshapeLayer : public Layer
  251. {
  252. public:
  253. MatShape newShapeDesc;
  254. Range newShapeRange;
  255. static Ptr<ReshapeLayer> create(const LayerParams& params);
  256. };
  257. class CV_EXPORTS FlattenLayer : public Layer
  258. {
  259. public:
  260. static Ptr<FlattenLayer> create(const LayerParams &params);
  261. };
  262. class CV_EXPORTS ConcatLayer : public Layer
  263. {
  264. public:
  265. int axis;
  266. /**
  267. * @brief Add zero padding in case of concatenation of blobs with different
  268. * spatial sizes.
  269. *
  270. * Details: https://github.com/torch/nn/blob/master/doc/containers.md#depthconcat
  271. */
  272. bool padding;
  273. static Ptr<ConcatLayer> create(const LayerParams &params);
  274. };
  275. class CV_EXPORTS SplitLayer : public Layer
  276. {
  277. public:
  278. int outputsCount; //!< Number of copies that will be produced (is ignored when negative).
  279. static Ptr<SplitLayer> create(const LayerParams &params);
  280. };
  281. /**
  282. * Slice layer has several modes:
  283. * 1. Caffe mode
  284. * @param[in] axis Axis of split operation
  285. * @param[in] slice_point Array of split points
  286. *
  287. * Number of output blobs equals to number of split points plus one. The
  288. * first blob is a slice on input from 0 to @p slice_point[0] - 1 by @p axis,
  289. * the second output blob is a slice of input from @p slice_point[0] to
  290. * @p slice_point[1] - 1 by @p axis and the last output blob is a slice of
  291. * input from @p slice_point[-1] up to the end of @p axis size.
  292. *
  293. * 2. TensorFlow mode
  294. * @param begin Vector of start indices
  295. * @param size Vector of sizes
  296. *
  297. * More convenient numpy-like slice. One and only output blob
  298. * is a slice `input[begin[0]:begin[0]+size[0], begin[1]:begin[1]+size[1], ...]`
  299. *
  300. * 3. Torch mode
  301. * @param axis Axis of split operation
  302. *
  303. * Split input blob on the equal parts by @p axis.
  304. */
  305. class CV_EXPORTS SliceLayer : public Layer
  306. {
  307. public:
  308. /**
  309. * @brief Vector of slice ranges.
  310. *
  311. * The first dimension equals number of output blobs.
  312. * Inner vector has slice ranges for the first number of input dimensions.
  313. */
  314. std::vector<std::vector<Range> > sliceRanges;
  315. std::vector<std::vector<int> > sliceSteps;
  316. int axis;
  317. int num_split;
  318. static Ptr<SliceLayer> create(const LayerParams &params);
  319. };
  320. class CV_EXPORTS PermuteLayer : public Layer
  321. {
  322. public:
  323. static Ptr<PermuteLayer> create(const LayerParams& params);
  324. };
  325. /**
  326. * Permute channels of 4-dimensional input blob.
  327. * @param group Number of groups to split input channels and pick in turns
  328. * into output blob.
  329. *
  330. * \f[ groupSize = \frac{number\ of\ channels}{group} \f]
  331. * \f[ output(n, c, h, w) = input(n, groupSize \times (c \% group) + \lfloor \frac{c}{group} \rfloor, h, w) \f]
  332. * Read more at https://arxiv.org/pdf/1707.01083.pdf
  333. */
  334. class CV_EXPORTS ShuffleChannelLayer : public Layer
  335. {
  336. public:
  337. static Ptr<Layer> create(const LayerParams& params);
  338. int group;
  339. };
  340. /**
  341. * @brief Adds extra values for specific axes.
  342. * @param paddings Vector of paddings in format
  343. * @code
  344. * [ pad_before, pad_after, // [0]th dimension
  345. * pad_before, pad_after, // [1]st dimension
  346. * ...
  347. * pad_before, pad_after ] // [n]th dimension
  348. * @endcode
  349. * that represents number of padded values at every dimension
  350. * starting from the first one. The rest of dimensions won't
  351. * be padded.
  352. * @param value Value to be padded. Defaults to zero.
  353. * @param type Padding type: 'constant', 'reflect'
  354. * @param input_dims Torch's parameter. If @p input_dims is not equal to the
  355. * actual input dimensionality then the `[0]th` dimension
  356. * is considered as a batch dimension and @p paddings are shifted
  357. * to a one dimension. Defaults to `-1` that means padding
  358. * corresponding to @p paddings.
  359. */
  360. class CV_EXPORTS PaddingLayer : public Layer
  361. {
  362. public:
  363. static Ptr<PaddingLayer> create(const LayerParams& params);
  364. };
  365. /* Activations */
  366. class CV_EXPORTS ActivationLayer : public Layer
  367. {
  368. public:
  369. virtual void forwardSlice(const float* src, float* dst, int len,
  370. size_t outPlaneSize, int cn0, int cn1) const = 0;
  371. };
  372. class CV_EXPORTS ReLULayer : public ActivationLayer
  373. {
  374. public:
  375. float negativeSlope;
  376. static Ptr<ReLULayer> create(const LayerParams &params);
  377. };
  378. class CV_EXPORTS ReLU6Layer : public ActivationLayer
  379. {
  380. public:
  381. float minValue, maxValue;
  382. static Ptr<ReLU6Layer> create(const LayerParams &params);
  383. };
  384. class CV_EXPORTS ChannelsPReLULayer : public ActivationLayer
  385. {
  386. public:
  387. static Ptr<Layer> create(const LayerParams& params);
  388. };
  389. class CV_EXPORTS ELULayer : public ActivationLayer
  390. {
  391. public:
  392. float alpha;
  393. static Ptr<ELULayer> create(const LayerParams &params);
  394. };
  395. class CV_EXPORTS TanHLayer : public ActivationLayer
  396. {
  397. public:
  398. static Ptr<TanHLayer> create(const LayerParams &params);
  399. };
  400. class CV_EXPORTS SwishLayer : public ActivationLayer
  401. {
  402. public:
  403. static Ptr<SwishLayer> create(const LayerParams &params);
  404. };
  405. class CV_EXPORTS MishLayer : public ActivationLayer
  406. {
  407. public:
  408. static Ptr<MishLayer> create(const LayerParams &params);
  409. };
  410. class CV_EXPORTS SigmoidLayer : public ActivationLayer
  411. {
  412. public:
  413. static Ptr<SigmoidLayer> create(const LayerParams &params);
  414. };
  415. class CV_EXPORTS BNLLLayer : public ActivationLayer
  416. {
  417. public:
  418. static Ptr<BNLLLayer> create(const LayerParams &params);
  419. };
  420. class CV_EXPORTS AbsLayer : public ActivationLayer
  421. {
  422. public:
  423. static Ptr<AbsLayer> create(const LayerParams &params);
  424. };
  425. class CV_EXPORTS PowerLayer : public ActivationLayer
  426. {
  427. public:
  428. float power, scale, shift;
  429. static Ptr<PowerLayer> create(const LayerParams &params);
  430. };
  431. class CV_EXPORTS ExpLayer : public ActivationLayer
  432. {
  433. public:
  434. float base, scale, shift;
  435. static Ptr<ExpLayer> create(const LayerParams &params);
  436. };
  437. /* Layers used in semantic segmentation */
  438. class CV_EXPORTS CropLayer : public Layer
  439. {
  440. public:
  441. static Ptr<Layer> create(const LayerParams &params);
  442. };
  443. /** @brief Element wise operation on inputs
  444. Extra optional parameters:
  445. - "operation" as string. Values are "sum" (default), "prod", "max", "div"
  446. - "coeff" as float array. Specify weights of inputs for SUM operation
  447. - "output_channels_mode" as string. Values are "same" (default, all input must have the same layout), "input_0", "input_0_truncate", "max_input_channels"
  448. */
  449. class CV_EXPORTS EltwiseLayer : public Layer
  450. {
  451. public:
  452. static Ptr<EltwiseLayer> create(const LayerParams &params);
  453. };
  454. class CV_EXPORTS BatchNormLayer : public ActivationLayer
  455. {
  456. public:
  457. bool hasWeights, hasBias;
  458. float epsilon;
  459. static Ptr<BatchNormLayer> create(const LayerParams &params);
  460. };
  461. class CV_EXPORTS MaxUnpoolLayer : public Layer
  462. {
  463. public:
  464. Size poolKernel;
  465. Size poolPad;
  466. Size poolStride;
  467. static Ptr<MaxUnpoolLayer> create(const LayerParams &params);
  468. };
  469. class CV_EXPORTS ScaleLayer : public Layer
  470. {
  471. public:
  472. bool hasBias;
  473. int axis;
  474. static Ptr<ScaleLayer> create(const LayerParams& params);
  475. };
  476. class CV_EXPORTS ShiftLayer : public Layer
  477. {
  478. public:
  479. static Ptr<Layer> create(const LayerParams& params);
  480. };
  481. class CV_EXPORTS DataAugmentationLayer : public Layer
  482. {
  483. public:
  484. static Ptr<DataAugmentationLayer> create(const LayerParams& params);
  485. };
  486. class CV_EXPORTS CorrelationLayer : public Layer
  487. {
  488. public:
  489. static Ptr<CorrelationLayer> create(const LayerParams& params);
  490. };
  491. class CV_EXPORTS AccumLayer : public Layer
  492. {
  493. public:
  494. static Ptr<AccumLayer> create(const LayerParams& params);
  495. };
  496. class CV_EXPORTS FlowWarpLayer : public Layer
  497. {
  498. public:
  499. static Ptr<FlowWarpLayer> create(const LayerParams& params);
  500. };
  501. class CV_EXPORTS PriorBoxLayer : public Layer
  502. {
  503. public:
  504. static Ptr<PriorBoxLayer> create(const LayerParams& params);
  505. };
  506. class CV_EXPORTS ReorgLayer : public Layer
  507. {
  508. public:
  509. static Ptr<ReorgLayer> create(const LayerParams& params);
  510. };
  511. class CV_EXPORTS RegionLayer : public Layer
  512. {
  513. public:
  514. static Ptr<RegionLayer> create(const LayerParams& params);
  515. };
  516. /**
  517. * @brief Detection output layer.
  518. *
  519. * The layer size is: @f$ (1 \times 1 \times N \times 7) @f$
  520. * where N is [keep_top_k] parameter multiplied by batch size. Each row is:
  521. * [image_id, label, confidence, xmin, ymin, xmax, ymax]
  522. * where image_id is the index of image input in the batch.
  523. */
  524. class CV_EXPORTS DetectionOutputLayer : public Layer
  525. {
  526. public:
  527. static Ptr<DetectionOutputLayer> create(const LayerParams& params);
  528. };
  529. /**
  530. * @brief \f$ L_p \f$ - normalization layer.
  531. * @param p Normalization factor. The most common `p = 1` for \f$ L_1 \f$ -
  532. * normalization or `p = 2` for \f$ L_2 \f$ - normalization or a custom one.
  533. * @param eps Parameter \f$ \epsilon \f$ to prevent a division by zero.
  534. * @param across_spatial If true, normalize an input across all non-batch dimensions.
  535. * Otherwise normalize an every channel separately.
  536. *
  537. * Across spatial:
  538. * @f[
  539. * norm = \sqrt[p]{\epsilon + \sum_{x, y, c} |src(x, y, c)|^p } \\
  540. * dst(x, y, c) = \frac{ src(x, y, c) }{norm}
  541. * @f]
  542. *
  543. * Channel wise normalization:
  544. * @f[
  545. * norm(c) = \sqrt[p]{\epsilon + \sum_{x, y} |src(x, y, c)|^p } \\
  546. * dst(x, y, c) = \frac{ src(x, y, c) }{norm(c)}
  547. * @f]
  548. *
  549. * Where `x, y` - spatial coordinates, `c` - channel.
  550. *
  551. * An every sample in the batch is normalized separately. Optionally,
  552. * output is scaled by the trained parameters.
  553. */
  554. class CV_EXPORTS NormalizeBBoxLayer : public Layer
  555. {
  556. public:
  557. float pnorm, epsilon;
  558. CV_DEPRECATED_EXTERNAL bool acrossSpatial;
  559. static Ptr<NormalizeBBoxLayer> create(const LayerParams& params);
  560. };
  561. /**
  562. * @brief Resize input 4-dimensional blob by nearest neighbor or bilinear strategy.
  563. *
  564. * Layer is used to support TensorFlow's resize_nearest_neighbor and resize_bilinear ops.
  565. */
  566. class CV_EXPORTS ResizeLayer : public Layer
  567. {
  568. public:
  569. static Ptr<ResizeLayer> create(const LayerParams& params);
  570. };
  571. /**
  572. * @brief Bilinear resize layer from https://github.com/cdmh/deeplab-public-ver2
  573. *
  574. * It differs from @ref ResizeLayer in output shape and resize scales computations.
  575. */
  576. class CV_EXPORTS InterpLayer : public Layer
  577. {
  578. public:
  579. static Ptr<Layer> create(const LayerParams& params);
  580. };
  581. class CV_EXPORTS ProposalLayer : public Layer
  582. {
  583. public:
  584. static Ptr<ProposalLayer> create(const LayerParams& params);
  585. };
  586. class CV_EXPORTS CropAndResizeLayer : public Layer
  587. {
  588. public:
  589. static Ptr<Layer> create(const LayerParams& params);
  590. };
  591. //! @}
  592. //! @}
  593. CV__DNN_EXPERIMENTAL_NS_END
  594. }
  595. }
  596. #endif