batch_norm.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 <memory>
20 
21 #include "ngraph/deprecated.hpp"
22 #include "ngraph/node.hpp"
23 #include "ngraph/op/op.hpp"
24 
25 namespace ngraph
26 {
27  namespace op
28  {
29  namespace v0
30  {
31  class NGRAPH_API BatchNormInference : public Op
32  {
33  public:
34  NGRAPH_RTTI_DECLARATION;
35  BatchNormInference() = default;
36  /// \param input [., C, ...]
37  /// \param gamma gamma scaling for normalized value. [C]
38  /// \param beta bias added to the scaled normalized value [C]
39  /// \param mean value for mean normalization [C]
40  /// \param variance value for variance normalization [C]
41  /// \param epsilon Avoids divsion by 0 if input has 0 variance
43  const Output<Node>& gamma,
44  const Output<Node>& beta,
45  const Output<Node>& mean,
46  const Output<Node>& variance,
47  double epsilon);
48 
49  bool visit_attributes(AttributeVisitor& visitor) override;
50 
51  void validate_and_infer_types() override;
52 
53  double get_eps_value() const { return m_epsilon; }
54  void set_eps_value(double epsilon) { m_epsilon = epsilon; }
55  std::shared_ptr<Node>
56  clone_with_new_inputs(const OutputVector& new_args) const override;
57 
58  private:
59  static constexpr size_t INPUT_GAMMA = 0;
60  static constexpr size_t INPUT_BETA = 1;
61  static constexpr size_t INPUT_DATA = 2;
62  static constexpr size_t INPUT_MEAN = 3;
63  static constexpr size_t INPUT_VARIANCE = 4;
64 
65  double m_epsilon;
66  };
67  } // namespace v0
68  namespace v5
69  {
70  class NGRAPH_API BatchNormInference : public Op
71  {
72  public:
73  NGRAPH_RTTI_DECLARATION;
74  BatchNormInference() = default;
75  /// \param input [., C, ...]
76  /// \param gamma gamma scaling for normalized value. [C]
77  /// \param beta bias added to the scaled normalized value [C]
78  /// \param mean value for mean normalization [C]
79  /// \param variance value for variance normalization [C]
80  /// \param epsilon Avoids divsion by 0 if input has 0 variance
82  const Output<Node>& gamma,
83  const Output<Node>& beta,
84  const Output<Node>& mean,
85  const Output<Node>& variance,
86  double epsilon);
87 
88  bool visit_attributes(AttributeVisitor& visitor) override;
89 
90  void validate_and_infer_types() override;
91 
92  double get_eps_value() const { return m_epsilon; }
93  void set_eps_value(double epsilon) { m_epsilon = epsilon; }
94  std::shared_ptr<Node>
95  clone_with_new_inputs(const OutputVector& new_args) const override;
96 
97  private:
98  static constexpr size_t INPUT_DATA = 0;
99  static constexpr size_t INPUT_GAMMA = 1;
100  static constexpr size_t INPUT_BETA = 2;
101  static constexpr size_t INPUT_MEAN = 3;
102  static constexpr size_t INPUT_VARIANCE = 4;
103 
104  double m_epsilon;
105  };
106  } // namespace v0
107  }
108 }
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
Definition: batch_norm.hpp:32
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
BatchNormInference(const Output< Node > &input, const Output< Node > &gamma, const Output< Node > &beta, const Output< Node > &mean, const Output< Node > &variance, double epsilon)
Definition: batch_norm.hpp:71
BatchNormInference(const Output< Node > &input, const Output< Node > &gamma, const Output< Node > &beta, const Output< Node > &mean, const Output< Node > &variance, double epsilon)
void validate_and_infer_types() override
Verifies that attributes and inputs are consistent and computes output shapes and element types....
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28