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_PRIOR_BOX_H_ 18 #define MINDSPORE_CORE_OPS_PRIOR_BOX_H_ 19 #include <memory> 20 #include <vector> 21 22 #include "mindapi/base/types.h" 23 #include "ops/base_operator.h" 24 25 namespace mindspore { 26 namespace ops { 27 constexpr auto kNamePriorBox = "PriorBox"; 28 /// \brief PriorBox defined PriorBox operator prototype of lite. 29 class MIND_API PriorBox : public BaseOperator { 30 public: 31 MIND_API_BASE_MEMBER(PriorBox); 32 /// \brief Constructor. PriorBox()33 PriorBox() : BaseOperator(kNamePriorBox) {} 34 35 /// \brief Method to init the op's attributes. 36 /// 37 /// \param[in] min_sizes Define the minimum side length of square boxes, can be multiple. 38 /// \param[in] max_sizes Define the maximum side length of square boxes as sqrt(min_size * max_size), can be multiple. 39 /// \param[in] aspect_ratios Define the aspect ratios of generated boxes. For each aspect_ratio, the width and height 40 /// are min_size * sqrt(aspect_ratio) and min_size / sqrt(aspect_ratio) respectively. 41 /// \param[in] variances Define variances for adjusting the prior boxes. 42 /// \param[in] image_size_w Define the width of the image. 43 /// \param[in] image_size_h Define the height of the image. 44 /// \param[in] step_w Define the ratio of the image width and the feature map width. 45 /// \param[in] step_h Define the ratio of the image height and the feature map height. 46 /// \param[in] clip Define whether clip the prior boxes to [0.0, 1.0]. 47 /// \param[in] flip Define whether flip aspect ratios. If true, with an aspect ratio r, ratio 1.0/r will be generated. 48 /// \param[in] offset Define the offset to the zero points of width and height. 49 void Init(const std::vector<int64_t> &min_sizes, const std::vector<int64_t> &max_sizes, 50 const std::vector<float> &aspect_ratios, const std::vector<float> &variances, const int64_t image_size_w, 51 const int64_t image_size_h, const float step_w, const float step_h, const bool clip, const bool flip, 52 const float offset); 53 54 /// \brief Method to set min_sizes attribute. 55 /// 56 /// \param[in] min_sizes Define the minimum side length of square boxes, can be multiple. 57 void set_min_sizes(const std::vector<int64_t> &min_sizes); 58 59 /// \brief Method to set max_sizes attribute. 60 /// 61 /// \param[in] max_sizes Define the maximum side length of square boxes as sqrt(min_size * max_size), can be multiple. 62 void set_max_sizes(const std::vector<int64_t> &max_sizes); 63 64 /// \brief Method to set aspect_ratios attribute. 65 /// 66 /// \param[in] aspect_ratios Define the aspect ratios of generated boxes. For each aspect_ratio, the width and height 67 /// are min_size * sqrt(aspect_ratio) and min_size / sqrt(aspect_ratio) respectively. 68 void set_aspect_ratios(const std::vector<float> &aspect_ratios); 69 70 /// \brief Method to set variances attribute. 71 /// 72 /// \param[in] variances Define variances for adjusting the prior boxes. 73 void set_variances(const std::vector<float> &variances); 74 75 /// \brief Method to set image_size_w attribute. 76 /// 77 /// \param[in] image_size_w Define the width of the image. 78 void set_image_size_w(const int64_t image_size_w); 79 80 /// \brief Method to set image_size_h attribute. 81 /// 82 /// \param[in] image_size_h Define the height of the image. 83 void set_image_size_h(const int64_t image_size_h); 84 85 /// \brief Method to set step_w attribute. 86 /// 87 /// \param[in] step_w Define the ratio of the image width and the feature map width. 88 void set_step_w(const float step_w); 89 90 /// \brief Method to set step_h attribute. 91 /// 92 /// \param[in] step_h Define the ratio of the image height and the feature map height. 93 void set_step_h(const float step_h); 94 95 /// \brief Method to set clip attribute. 96 /// 97 /// \param[in] clip Define whether clip the prior boxes to [0.0, 1.0]. 98 void set_clip(const bool clip); 99 100 /// \brief Method to set flip attribute. 101 /// 102 /// \param[in] flip Define whether flip aspect ratios. If true, with an aspect ratio r, ratio 1.0/r will be generated. 103 void set_flip(const bool flip); 104 105 /// \brief Method to set offset attribute. 106 /// 107 /// \param[in] offset Define the offset to the zero points of width and height. 108 void set_offset(const float offset); 109 110 /// \brief Method to get min_sizes attribute. 111 /// 112 /// \return min_sizes attribute. 113 std::vector<int64_t> get_min_sizes() const; 114 115 /// \brief Method to get max_sizes attribute. 116 /// 117 /// \return max_sizes attribute. 118 std::vector<int64_t> get_max_sizes() const; 119 120 /// \brief Method to get aspect_ratios attribute. 121 /// 122 /// \return aspect_ratios attribute. 123 std::vector<float> get_aspect_ratios() const; 124 125 /// \brief Method to get variances attribute. 126 /// 127 /// \return variances attribute. 128 std::vector<float> get_variances() const; 129 130 /// \brief Method to get image_size_w attribute. 131 /// 132 /// \return image_size_w attribute. 133 int64_t get_image_size_w() const; 134 135 /// \brief Method to get image_size_h attribute. 136 /// 137 /// \return image_size_h attribute. 138 int64_t get_image_size_h() const; 139 140 /// \brief Method to get step_w attribute. 141 /// 142 /// \return step_w attribute. 143 float get_step_w() const; 144 145 /// \brief Method to get step_h attribute. 146 /// 147 /// \return step_h attribute. 148 float get_step_h() const; 149 150 /// \brief Method to get flip attribute. 151 /// 152 /// \return flip attribute. 153 bool get_flip() const; 154 155 /// \brief Method to get clip attribute. 156 /// 157 /// \return clip attribute. 158 bool get_clip() const; 159 160 /// \brief Method to get offset attribute. 161 /// 162 /// \return offset attribute. 163 float get_offset() const; 164 }; 165 166 MIND_API abstract::AbstractBasePtr PriorBoxInfer(const abstract::AnalysisEnginePtr &, const PrimitivePtr &primitive, 167 const std::vector<abstract::AbstractBasePtr> &input_args); 168 } // namespace ops 169 } // namespace mindspore 170 171 #endif // MINDSPORE_CORE_OPS_PRIOR_BOX_H_ 172