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_CONV2D_H_ 18 #define MINDSPORE_CORE_OPS_CONV2D_H_ 19 #include <map> 20 #include <vector> 21 #include <string> 22 #include <memory> 23 24 #include "ops/op_utils.h" 25 #include "ops/primitive_c.h" 26 #include "abstract/abstract_value.h" 27 #include "utils/check_convert_utils.h" 28 namespace mindspore { 29 namespace ops { 30 constexpr auto kNameConv2D = "Conv2D"; 31 /// \brief 2D convolution layer. Refer to Python API @ref mindspore.ops.Conv2D for more details. 32 class MS_CORE_API Conv2D : public PrimitiveC { 33 public: 34 /// \brief Constructor. Conv2D()35 Conv2D() : PrimitiveC(kNameConv2D) { InitIOName({"x", "w"}, {"output"}); } Conv2D(const std::string k_name)36 explicit Conv2D(const std::string k_name) : PrimitiveC(k_name) { InitIOName({"x", "w"}, {"output"}); } 37 /// \brief Destructor. 38 ~Conv2D() = default; 39 MS_DECLARE_PARENT(Conv2D, PrimitiveC); 40 /// \brief Init. Refer to the parameters of Python API @ref mindspore.ops.Conv2D for the inputs. 41 void Init(int64_t out_channel, const std::vector<int64_t> &kernel_size, int64_t mode = 1, 42 const PadMode &pad_mode = VALID, const std::vector<int64_t> &pad = {0, 0, 0, 0}, 43 const std::vector<int64_t> &stride = {1, 1, 1, 1}, const std::vector<int64_t> &dilation = {1, 1, 1, 1}, 44 int64_t group = 1, const Format &format = NCHW); 45 /// \brief Set kernel_size. 46 void set_kernel_size(const std::vector<int64_t> &kernel_size); 47 /// \brief Set stride. 48 void set_stride(const std::vector<int64_t> &stride); 49 /// \brief Set dilation. 50 void set_dilation(const std::vector<int64_t> &dilation); 51 /// \brief Set pad_mode. 52 void set_pad_mode(const PadMode &pad_mode); 53 /// \brief Set pad. 54 void set_pad(const std::vector<int64_t> &pad); 55 /// \brief Set mode. 56 void set_mode(int64_t mode); 57 /// \brief Set group. 58 void set_group(int64_t group); 59 /// \brief Set out_channel. 60 void set_out_channel(int64_t out_channel); 61 /// \brief Set format. 62 void set_format(const Format &format); 63 /// \brief Get kernel_size. 64 /// 65 /// \return kernel_size. 66 std::vector<int64_t> get_kernel_size() const; 67 /// \brief Get stride. 68 /// 69 /// \return stride. 70 std::vector<int64_t> get_stride() const; 71 /// \brief Get dilation. 72 /// 73 /// \return dilation. 74 std::vector<int64_t> get_dilation() const; 75 /// \brief Get pad_mode. 76 /// 77 /// \return pad_mode. 78 PadMode get_pad_mode() const; 79 /// \brief Get pad. 80 /// 81 /// \return pad. 82 std::vector<int64_t> get_pad() const; 83 /// \brief Get mode. 84 /// 85 /// \return mode. 86 int64_t get_mode() const; 87 /// \brief Get group. 88 /// 89 /// \return group. 90 int64_t get_group() const; 91 /// \brief Get out_channel. 92 /// 93 /// \return out_channel. 94 int64_t get_out_channel() const; 95 /// \brief Get format. 96 /// 97 /// \return format. 98 Format get_format() const; 99 }; 100 AbstractBasePtr Conv2dInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, 101 const std::vector<AbstractBasePtr> &input_args); 102 using PrimConv2dPtr = std::shared_ptr<Conv2D>; 103 } // namespace ops 104 } // namespace mindspore 105 #endif // MINDSPORE_CORE_OPS_CONV2D_H_ 106