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