Publishing 2019 R3 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / api / lrn.hpp
1 /*
2 // Copyright (c) 2016 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #pragma once
19 #include "primitive.hpp"
20
21 namespace cldnn {
22 /// @addtogroup cpp_api C++ API
23 /// @{
24 /// @addtogroup cpp_topology Network Topology
25 /// @{
26 /// @addtogroup cpp_primitives Primitives
27 /// @{
28
29 typedef enum { /*:int32_t*/
30     lrn_norm_region_across_channel,
31     lrn_norm_region_within_channel
32 } lrn_norm_region;
33
34 /// @brief Local response normalization
35 /// @details LRN layer as described in chapter 3.3 of "ImageNet Classification with Deep Convolutional
36 /// Neural Networks" by Khrizevsky, Sutskever, Hinton. @n See: http://www.cs.toronto.edu/~fritz/absps/imagenet.pdf
37 /// @par Alogrithm:
38 ///   b(i,x,y) = a(i,x,y) / (k+alpha*sum(min(N-1, i+n/2); j=max(0,i-n/2); a(j,x,y)^2))
39 /// @par Where:
40 ///   @li b(i,x,y) : value at x, y from i-th feature map after normalization
41 ///   @li a(i,x,y) : value at x, y from i-th feature map before normalization
42 ///   @li N : number of feature maps
43 ///   @li n : size of normalization
44 ///   @li k, alpha, beta : hyper parameters (equal to 2, 10e-4, 0.75 in paper).
45 struct lrn : public primitive_base<lrn> {
46     CLDNN_DECLARE_PRIMITIVE(lrn)
47
48     /// @brief Constructs LRN primitive.
49     /// @param id This primitive id.
50     /// @param input Input primitive id.
51     /// @param size Size of normalization.
52     /// @param k Hyper parameter "k".
53     /// @param alpha Hyper parameter "alpha".
54     /// @param beta Hyper parameter "beta".
55     /// @param lrn_norm_region Normalize across or within channel
56     lrn(const primitive_id& id,
57         const primitive_id& input,
58         uint32_t size,
59         float k,
60         float alpha,
61         float beta,
62         lrn_norm_region lrn_norm_region,
63         const padding& output_padding = padding())
64         : primitive_base(id, {input}, output_padding),
65           size(size),
66           k(k),
67           alpha(alpha),
68           beta(beta),
69           norm_region(lrn_norm_region) {}
70
71     /// @brief Size of normalization.
72     uint32_t size;
73     /// @brief Hyper parameter "k".
74     float k;
75     /// @brief Hyper parameter "alpha".
76     float alpha;
77     /// @brief Hyper parameter "beta".
78     float beta;
79     /// @brief Normalize across or within channel
80     lrn_norm_region norm_region;
81 };
82 /// @}
83 /// @}
84 /// @}
85 }  // namespace cldnn