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