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