• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 Huawei Technologies Co., Ltd
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 #ifndef MINDSPORE_CORE_OPS_FUSED_BATCH_NORM_H_
18 #define MINDSPORE_CORE_OPS_FUSED_BATCH_NORM_H_
19 #include <map>
20 #include <vector>
21 #include <string>
22 #include <memory>
23 #include "ops/primitive_c.h"
24 #include "abstract/abstract_value.h"
25 #include "utils/check_convert_utils.h"
26 
27 namespace mindspore {
28 namespace ops {
29 constexpr auto kNameFusedBatchNorm = "FusedBatchNorm";
30 /// \brief FusedBatchNorm defined Enhanced BatchNorm operator prototype.
31 class MS_CORE_API FusedBatchNorm : public PrimitiveC {
32  public:
33   /// \brief Constructor.
FusedBatchNorm()34   FusedBatchNorm() : PrimitiveC(kNameFusedBatchNorm) {
35     InitIOName({"x", "scale", "b", "mean", "variance"},
36                {"y", "running_mean", "running_variance", "save_mean", "save_inv_variance"});
37   }
38 
39   /// \brief Destructor.
40   ~FusedBatchNorm() = default;
41 
42   MS_DECLARE_PARENT(FusedBatchNorm, PrimitiveC);
43 
44   /// \brief Method to init the op's attributes.
45   ///
46   /// \param[in] mode Define the mode of batchnorm, which is useless.
47   /// \param[in] epsilon Define a small value added for numerical stability, which is used to avoid that divisor is
48   ///            zero.
49   /// \param[in] momentum Define the hyper parameter to compute moving average for running_mean and running_var.
50   void Init(const int64_t mode = 0, const float epsilon = 1e-5, const float momentum = 0.1);
51 
52   /// \brief Method to set mode attribute, which has been abandoned.
53   ///
54   /// \param[in] mode Define the mode of batchnorm, which is useless.
55   void set_mode(const int64_t mode);
56 
57   /// \brief Method to set epsilon attribute.
58   ///
59   /// \param[in] epsilon Define a small value added for numerical stability, which is used to avoid that divisor is
60   ///            zero.
61   void set_epsilon(const float epsilon);
62 
63   /// \brief Method to set momentum attribute.
64   ///
65   /// \param[in] momentum Define the hyper parameter to compute moving average for running_mean and running_var.
66   void set_momentum(const float momentum);
67 
68   /// \brief Method to get mode attribute, which has been abandoned.
69   int64_t get_mode() const;
70 
71   /// \brief Method to get epsilon attribute.
72   ///
73   /// \return a small float value.
74   float get_epsilon() const;
75 
76   /// \brief Method to get momentum attribute.
77   ///
78   /// \return the hyper parameter .
79   float get_momentum() const;
80 };
81 }  // namespace ops
82 }  // namespace mindspore
83 
84 #endif  // MINDSPORE_CORE_OPS_FUSED_BATCH_NORM_H_
85