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_AVG_POOL_H_ 18 #define MINDSPORE_CORE_OPS_AVG_POOL_H_ 19 20 #include <map> 21 #include <vector> 22 #include <string> 23 #include <memory> 24 #include "ops/primitive_c.h" 25 #include "abstract/abstract_value.h" 26 #include "utils/check_convert_utils.h" 27 28 namespace mindspore { 29 namespace ops { 30 constexpr auto kNameAvgPool = "AvgPool"; 31 /// \brief Average pooling operation. Refer to Python API @ref mindspore.ops.AvgPool for more details. 32 class MS_CORE_API AvgPool : public PrimitiveC { 33 public: 34 /// \brief Constructor. AvgPool()35 AvgPool() : PrimitiveC(kNameAvgPool) { InitIOName({"x"}, {"output"}); } AvgPool(const std::string k_name)36 explicit AvgPool(const std::string k_name) : PrimitiveC(k_name) { InitIOName({"x"}, {"output"}); } 37 /// \brief Destructor. 38 ~AvgPool() = default; 39 MS_DECLARE_PARENT(AvgPool, PrimitiveC); 40 /// \brief Init. Refer to the parameters of Python API @ref mindspore.ops.AvgPool for the inputs. 41 void Init(const std::vector<int64_t> &kernel_size = {1}, const std::vector<int64_t> &stride = {1}, 42 const PadMode &pad_mode = VALID, const Format &format = NCHW, 43 const std::vector<int64_t> &pad = {0, 0, 0, 0}, const RoundMode &round_mode = FLOOR); 44 /// \brief Set pad_mode. 45 void set_pad_mode(const PadMode &pad_mode); 46 /// \brief Set kernel_size. 47 void set_kernel_size(const std::vector<int64_t> &kernel_size); 48 /// \brief Set strides. 49 void set_strides(const std::vector<int64_t> &strides); 50 /// \brief Set format. 51 void set_format(const Format &format); 52 /// \brief Set pad. 53 void set_pad(const std::vector<int64_t> &pad); 54 /// \brief Set round_mode. 55 void set_round_mode(const RoundMode &round_mode); 56 57 /// \brief Get kernel_size. 58 /// 59 /// \return kernel_size. 60 std::vector<int64_t> get_kernel_size() const; 61 /// \brief Get strides. 62 /// 63 /// \return strides. 64 std::vector<int64_t> get_strides() const; 65 /// \brief Get pad_mode. 66 /// 67 /// \return pad_mode. 68 PadMode get_pad_mode() const; 69 /// \brief Get format. 70 /// 71 /// \return format. 72 Format get_format() const; 73 /// \brief Get pad. 74 /// 75 /// \return pad. 76 std::vector<int64_t> get_pad() const; 77 /// \brief Get round_mode. 78 /// 79 /// \return round_mode. 80 RoundMode get_round_mode() const; 81 }; 82 83 AbstractBasePtr AvgPoolInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, 84 const std::vector<AbstractBasePtr> &input_args); 85 using PrimAvgPoolPtr = std::shared_ptr<AvgPool>; 86 } // namespace ops 87 } // namespace mindspore 88 89 #endif // MINDSPORE_CORE_OPS_AVG_POOL_H_ 90