mvn.hpp
1 //*****************************************************************************
2 // Copyright 2017-2020 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/node.hpp"
20 #include "ngraph/op/op.hpp"
21 #include "ngraph/op/util/fused_op.hpp"
22 
23 NGRAPH_SUPPRESS_DEPRECATED_START
24 
25 namespace ngraph
26 {
27  namespace op
28  {
29  namespace v0
30  {
31  /// \brief Operator performing Mean Variance Normalization
32  ///
33  class NGRAPH_API MVN : public ngraph::op::util::FusedOp
34  {
35  public:
36  static constexpr NodeTypeInfo type_info{"MVN", 0};
37  const NodeTypeInfo& get_type_info() const override { return type_info; }
38  MVN() = default;
39  /// \brief Constructs an MVN operation.
40  ///
41  /// \param data Input tensor with data
42  /// \param normalize_variance flag that denotes whether to perform variance
43  /// normalization.
44  /// \param across_channels flag that denotes if mean values are shared across
45  /// channels.
46  /// \param eps the number to be added to the variance to avoid division by zero when
47  /// normalizing the value
48  ///
49  MVN(const Output<Node>& data,
50  bool across_channels = true,
51  bool normalize_variance = true,
52  double eps = 1e-9);
53 
54  /// \brief Constructs an MVN operation.
55  ///
56  /// \param data Input tensor with data
57  /// \param reduction_axes A list of axes, along which to reduce.
58  /// \param normalize_variance flag that denotes whether to perform variance
59  /// normalization.
60  /// \param eps the number to be added to the variance to avoid division by zero when
61  /// normalizing the value
62  ///
63  MVN(const Output<Node>& data,
64  AxisSet reduction_axes,
65  bool normalize_variance = true,
66  double eps = 1e-9);
67 
68  virtual OutputVector decompose_op() const override;
69 
70  virtual void validate_and_infer_types() override;
71 
72  virtual bool visit_attributes(AttributeVisitor& visitor) override;
73 
74  virtual std::shared_ptr<Node>
75  clone_with_new_inputs(const OutputVector& new_args) const override;
76 
77  double get_eps() const { return m_eps; }
78  bool get_across_channels() const { return m_across_channels; }
79  bool get_normalize_variance() const { return m_normalize_variance; }
80  AxisSet get_reduction_axes() const { return m_reduction_axes; }
81  void set_reduction_axes(AxisSet axes) { m_reduction_axes = axes; }
82  private:
83  double m_eps = 1e-9;
84  bool m_across_channels;
85  bool m_normalize_variance;
86  AxisSet m_reduction_axes;
87  };
88  }
89  using v0::MVN;
90  } // namespace op
91 } // namespace ngraph
92 
93 NGRAPH_SUPPRESS_DEPRECATED_END
ngraph::AxisSet
A set of axes.
Definition: axis_set.hpp:31
ngraph::op::v0::MVN::MVN
MVN(const Output< Node > &data, AxisSet reduction_axes, bool normalize_variance=true, double eps=1e-9)
Constructs an MVN operation.
ngraph::op::v0::MVN
Operator performing Mean Variance Normalization.
Definition: mvn.hpp:34
ngraph::op::v0::MVN::MVN
MVN(const Output< Node > &data, bool across_channels=true, bool normalize_variance=true, double eps=1e-9)
Constructs an MVN operation.
ngraph
The Intel nGraph C++ API.
Definition: attribute_adapter.hpp:28
ngraph::AttributeVisitor
Visits the attributes of a node, primarily for serialization-like tasks.
Definition: attribute_visitor.hpp:70