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_RESIZE_H_ 18 #define MINDSPORE_CORE_OPS_RESIZE_H_ 19 #include <memory> 20 21 #include "mindapi/base/format.h" 22 #include "mindapi/base/types.h" 23 #include "ops/base_operator.h" 24 25 namespace mindspore { 26 namespace ops { 27 constexpr auto kNameResize = "Resize"; 28 /// \brief Resize defined the Resize operator prototype of lite. 29 class MIND_API Resize : public BaseOperator { 30 public: 31 MIND_API_BASE_MEMBER(Resize); 32 /// \brief Constructor. Resize()33 Resize() : BaseOperator(kNameResize) {} 34 35 /// \brief Method to init the op's attributes. 36 /// 37 /// \param[in] format Define the format of the input, which only support NHWC on lite. 38 /// \param[in] method Define the mode of resizing. 39 /// \param[in] new_height Define the height of the output. 40 /// \param[in] new_width Define the width of the output. 41 /// \param[in] preserve_aspect_ratio Define a boolean to indicate keep the aspect radio with the input. Default is 42 /// false. 43 /// \param[in] coordinate_transform_mode Define the rule to map coordinate. 44 /// \param[in] cubic_coeff Define a coefficient only used in cubic interpolation. 45 /// \param[in] exclude_outside Define a value to indicate whether to set the outside of the sampling area as 0. If the 46 /// value is 1, the outside area will be set as 0. Default is 0. 47 /// \param[in] extrapolation_value Define a value that will be used to fill the outside of original area if possible. 48 /// \param[in] nearest_mode Define the rule how to get nearest pixel. 49 void Init(const Format format, const ResizeMethod method, const int64_t new_height, const int64_t new_width, 50 const bool preserve_aspect_ratio, const CoordinateTransformMode coordinate_transform_mode, 51 const float cubic_coeff, const int64_t exclude_outside, const float extrapolation_value, 52 const NearestMode nearest_mode); 53 54 /// \brief Method to set format attribute. 55 /// 56 /// \param[in] format Define the format of the input, which only support NHWC on lite. 57 void set_format(const Format format); 58 59 /// \brief Method to set method attribute. 60 /// 61 /// \param[in] method Define the mode of resizing. 62 void set_method(const ResizeMethod method); 63 64 /// \brief Method to set new_height attribute. 65 /// 66 /// \param[in] new_height Define the height of the output. 67 void set_new_height(const int64_t new_height); 68 69 /// \brief Method to set new_width attribute. 70 /// 71 /// \param[in] new_width Define the width of the output. 72 void set_new_width(const int64_t new_width); 73 74 /// \brief Method to set preserve_aspect_ratio attribute. 75 /// 76 /// \param[in] preserve_aspect_ratio Define a boolean to indicate keep the aspect radio with the input. Default is 77 /// false. 78 void set_preserve_aspect_ratio(const bool preserve_aspect_ratio); 79 80 /// \brief Method to set coordinate_transform_mode attribute. 81 /// 82 /// \param[in] coordinate_transform_mode Define the rule to map coordinate. 83 void set_coordinate_transform_mode(const CoordinateTransformMode coordinate_transform_mode); 84 85 /// \brief Method to set cubic_coeff attribute. 86 /// 87 /// \param[in] cubic_coeff Define a coefficient only used in cubic interpolation. 88 void set_cubic_coeff(const float cubic_coeff); 89 90 /// \brief Method to set exclude_outside attribute. 91 /// 92 /// \param[in] exclude_outside Define a value to indicate whether to set the outside of the sampling area as 0. If the 93 /// value is 1, the outside area will be set as 0. Default is 0. 94 void set_exclude_outside(const int64_t exclude_outside); 95 96 /// \brief Method to set extrapolation_value attribute. 97 /// 98 /// \param[in] extrapolation_value Define a value that will be used to fill the outside of original area if possible. 99 void set_extrapolation_value(const float extrapolation_value); 100 101 /// \brief Method to set nearest_mode attribute. 102 /// 103 /// \param[in] nearest_mode Define the rule how to get nearest pixel. 104 void set_nearest_mode(const NearestMode nearest_mode); 105 106 /// \brief Method to get format attribute. 107 /// 108 /// \return the format of the input. 109 Format get_format() const; 110 111 /// \brief Method to get method attribute. 112 /// 113 /// \return the mode of resizing. 114 ResizeMethod get_method() const; 115 116 /// \brief Method to get new_height attribute. 117 /// 118 /// \return the height of the output. 119 int64_t get_new_height() const; 120 121 /// \brief Method to get new_width attribute. 122 /// 123 /// \return the width of the output. 124 int64_t get_new_width() const; 125 126 /// \brief Method to get preserve_aspect_ratio attribute. 127 /// 128 /// \return a boolean value. 129 bool get_preserve_aspect_ratio() const; 130 131 /// \brief Method to get coordinate_transform_mode attribute. 132 /// 133 /// \return the rule to map coordinate 134 CoordinateTransformMode get_coordinate_transform_mode() const; 135 136 /// \brief Method to get cubic_coeff attribute. 137 /// 138 /// \return a coefficient used in cubic interpolation 139 float get_cubic_coeff() const; 140 141 /// \brief Method to get exclude_outside attribute. 142 /// 143 /// \return a value to indicate whether to set the outside of the sampling area as 0. 144 int64_t get_exclude_outside() const; 145 146 /// \brief Method to get extrapolation_value attribute. 147 /// 148 /// \return a value used to fill the outside of original area if possible 149 float get_extrapolation_value() const; 150 151 /// \brief Method to get nearest_mode attribute. 152 /// 153 /// \return the rule to get nearest pixel. 154 NearestMode get_nearest_mode() const; 155 }; 156 } // namespace ops 157 } // namespace mindspore 158 159 #endif // MINDSPORE_CORE_OPS_RESIZE_H_ 160