lrn.hpp
1 //*****************************************************************************
2 // Copyright 2017-2021 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 #pragma once
18 
19 #include "ngraph/op/op.hpp"
20 
21 namespace ngraph
22 {
23  namespace op
24  {
25  namespace v0
26  {
27  // clang-format off
28  /// \brief Elementwise Local Response Normalization (LRN) operation.
29  ///
30  /// ## Inputs
31  ///
32  /// | | Type | Description |
33  /// | ----- | --------------------------------------- | ----------------------------------------------- |
34  /// | `arg` | \f$N[n, c, d_1,\dots,d_n]~(n \geq 0)\f$ | A tensor of any shape and numeric element type. |
35  ///
36  /// ## Output
37  ///
38  /// | Type | Description |
39  /// | ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
40  /// | \f$N[n, c, d_1,\dots,d_n]\f$ | The tensor \f$T\f$, where \f$T[n, c, d_1,\dots,d_n] = \frac{N[n,i,d_1,\dots,d_n]}{ (bias + alpha * (\sum_{i=max(0,(nsize-1)/2)}^{min(C, (nsize-1)/2)+1} N[n,i,d_1,\dots,d_n]^{2}) ^ {2})}\f$ |
41  // clang-format on
42  class NGRAPH_API LRN : public Op
43  {
44  public:
45  static constexpr NodeTypeInfo type_info{"LRN", 0};
46  const NodeTypeInfo& get_type_info() const override { return type_info; }
47  /// \brief Constructs a LRN operation.
48  LRN() = default;
49  /// \brief Constructs a LRN operation.
50  ///
51  /// \param arg Node that produces the input tensor.
52  LRN(const Output<Node>& arg, double alpha, double beta, double bias, size_t size);
53 
54  LRN(const Output<Node>& arg,
55  const Output<Node>& axes,
56  double alpha,
57  double beta,
58  double bias,
59  size_t size);
60 
61  bool visit_attributes(AttributeVisitor& visitor) override;
62  virtual std::shared_ptr<Node>
63  clone_with_new_inputs(const OutputVector& new_args) const override;
64  void validate_and_infer_types() override;
65 
66  double get_alpha() const { return m_alpha; }
67  void set_alpha(double alpha) { m_alpha = alpha; }
68  double get_beta() const { return m_beta; }
69  void set_beta(double beta) { m_beta = beta; }
70  double get_bias() const { return m_bias; }
71  void set_bias(double bias) { m_bias = bias; }
72  size_t get_nsize() const { return m_size; }
73  void set_nsize(size_t size) { m_size = size; }
74  AxisSet get_reduction_axes() const;
75 
76  protected:
77  double m_alpha;
78  double m_beta;
79  double m_bias;
80  size_t m_size;
81  };
82  }
83  using v0::LRN;
84  }
85 }
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:71
A handle for one of a node's outputs.
Definition: node_output.hpp:42
Root of all actual ops.
Definition: op.hpp:29
Elementwise Local Response Normalization (LRN) operation.
Definition: lrn.hpp:43
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
LRN()=default
Constructs a LRN operation.
LRN(const Output< Node > &arg, double alpha, double beta, double bias, size_t size)
Constructs a LRN operation.
const NodeTypeInfo & get_type_info() const override
Definition: lrn.hpp:46
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
Definition: type.hpp:39