1 /** 2 * Copyright 2020-2021 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_MAX_POOL_FUSION_H_ 18 #define MINDSPORE_CORE_OPS_MAX_POOL_FUSION_H_ 19 #include <vector> 20 #include <memory> 21 22 #include "ops/max_pool.h" 23 #include "ops/op_utils.h" 24 #include "utils/check_convert_utils.h" 25 26 namespace mindspore { 27 namespace ops { 28 constexpr auto kNameMaxPoolFusion = "MaxPoolFusion"; 29 /// \brief MaxPoolFusion defined MaxPool operator prototype of lite. 30 class MS_CORE_API MaxPoolFusion : public MaxPool { 31 public: 32 /// \brief Constructor. MaxPoolFusion()33 MaxPoolFusion() : MaxPool(kNameMaxPoolFusion) { InitIOName({"x"}, {"output"}); } 34 35 /// \brief Destructor. 36 ~MaxPoolFusion() = default; 37 38 MS_DECLARE_PARENT(MaxPoolFusion, MaxPool); 39 40 /// \brief Method to init the op's attributes. 41 /// 42 /// \param[in] kernel_size Define the size of the kernel. 43 /// \param[in] stride Define the moving size of the kernel. 44 /// \param[in] pad_mode Define the padding method. 45 /// \param[in] format Define the format of input tensor. 46 /// \param[in] pad Define the concrete padding value on each dimension 47 /// \param[in] round_mode Define numerical operation mode of the output tensor. 48 /// \param[in] global Define a boolean value to indicate whether to do global pooling. If true, kernel_size will be 49 /// useless. 50 /// \param[in] activation_type Define the activation type. 51 void Init(const std::vector<int64_t> &kernel_size = {1}, const std::vector<int64_t> &stride = {1}, 52 const PadMode &pad_mode = VALID, const Format &format = NCHW, 53 const std::vector<int64_t> &pad = {0, 0, 0, 0}, const RoundMode &round_mode = FLOOR, 54 const bool global = false, const ActivationType activation_type = NO_ACTIVATION); 55 56 /// \brief Method to set global attribute. 57 /// 58 /// \param[in] global Define a boolean value to indicate whether to do global pooling. If true, kernel_size will be 59 /// useless. 60 void set_global(const bool global); 61 62 /// \brief Method to set activation type. 63 /// 64 /// \param[in] activation_type Define the activation type. 65 void set_activation_type(const ActivationType activation_type); 66 67 /// \brief Method to get global attribute. 68 /// 69 /// \return a boolean value to indicate whether to do global pooling. If true, kernel_size will be useless. 70 bool get_global() const; 71 72 /// \brief Method to get activation type. 73 /// 74 /// \return activation type. 75 ActivationType get_activation_type() const; 76 }; 77 78 AbstractBasePtr MaxPoolFusionInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, 79 const std::vector<AbstractBasePtr> &input_args); 80 using PrimMaxPoolFusionPtr = std::shared_ptr<MaxPoolFusion>; 81 } // namespace ops 82 } // namespace mindspore 83 84 #endif // MINDSPORE_CORE_OPS_MAX_POOL_FUSION_H_ 85