tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
image.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
24 #ifndef TVM_RELAY_ATTRS_IMAGE_H_
25 #define TVM_RELAY_ATTRS_IMAGE_H_
26 
27 #include <tvm/ir/attrs.h>
28 #include <tvm/relay/base.h>
29 
30 #include <string>
31 
32 namespace tvm {
33 namespace relay {
34 
36 struct Resize1DAttrs : public tvm::AttrsNode<Resize1DAttrs> {
39  std::string layout;
40  std::string method;
42  std::string rounding_method;
43  double cubic_alpha;
47 
48  TVM_DECLARE_ATTRS(Resize1DAttrs, "relay.attrs.Resize1DAttrs") {
49  TVM_ATTR_FIELD(size).set_default(NullValue<Array<IndexExpr>>()).describe("Output Size.");
50  TVM_ATTR_FIELD(roi)
51  .set_default(NullValue<Array<FloatImm>>())
52  .describe("Region of Interest for coordinate transformation mode 'tf_crop_and_resize'");
53  TVM_ATTR_FIELD(layout).set_default("NCW").describe(
54  "Dimension ordering of input data. Can be 'NCW', 'NWC', etc."
55  "'N', 'C', 'W' stands for batch, channel and width"
56  "dimensions respectively. Resize is applied on the"
57  "'W' dimension.");
58  TVM_ATTR_FIELD(method).set_default("linear").describe(
59  "Specify the mode to use for scaling."
60  "nearest_neighbor - Nearest Neighbor"
61  "linear - Linear Interpolation"
62  "cubic - Cubic Interpolation");
63  TVM_ATTR_FIELD(coordinate_transformation_mode)
64  .set_default("half_pixel")
65  .describe(
66  "Describes how to transform the coordinate in the resized tensor"
67  "to the coordinate in the original tensor."
68  "Refer to the ONNX Resize operator specification for details"
69  "Available options are half_pixel, align_corners and asymmetric");
70  TVM_ATTR_FIELD(rounding_method)
71  .set_default("round")
72  .describe(
73  "indicates how to find the \"nearest\" pixel in nearest_neighbor method"
74  "Available options are round, floor, and ceil.");
75  TVM_ATTR_FIELD(cubic_alpha)
76  .set_default(-0.5)
77  .describe("Spline Coefficient for cubic interpolation");
78  TVM_ATTR_FIELD(cubic_exclude)
79  .set_default(0)
80  .describe("Flag to exclude exterior of the image during cubic interpolation");
81  TVM_ATTR_FIELD(extrapolation_value)
82  .set_default(0.0)
83  .describe("Value to return when roi is outside of the image");
84  TVM_ATTR_FIELD(out_dtype).set_default(NullValue<DataType>()).describe("Output data type.");
85  }
86 };
87 
89 struct Resize2DAttrs : public tvm::AttrsNode<Resize2DAttrs> {
92  std::string layout;
93  std::string method;
95  std::string rounding_method;
96  double cubic_alpha;
100 
101  TVM_DECLARE_ATTRS(Resize2DAttrs, "relay.attrs.Resize2DAttrs") {
102  TVM_ATTR_FIELD(size).set_default(NullValue<Array<IndexExpr>>()).describe("Output Size.");
103  TVM_ATTR_FIELD(roi)
104  .set_default(NullValue<Array<FloatImm>>())
105  .describe("Region of Interest for coordinate transformation mode 'tf_crop_and_resize'");
106  TVM_ATTR_FIELD(layout).set_default("NCHW").describe(
107  "Dimension ordering of input data. Can be 'NCHW', 'NHWC', etc."
108  "'N', 'C', 'H', 'W' stands for batch, channel, height, and width"
109  "dimensions respectively. Resize is applied on the 'H' and"
110  "'W' dimensions.");
111  TVM_ATTR_FIELD(method).set_default("linear").describe(
112  "Specify the mode to use for scaling."
113  "nearest_neighbor - Nearest Neighbor"
114  "linear - Bilinear Interpolation"
115  "cubic - Bicubic Interpolation");
116  TVM_ATTR_FIELD(coordinate_transformation_mode)
117  .set_default("half_pixel")
118  .describe(
119  "Describes how to transform the coordinate in the resized tensor"
120  "to the coordinate in the original tensor."
121  "Refer to the ONNX Resize operator specification for details"
122  "Available options are half_pixel, align_corners and asymmetric");
123  TVM_ATTR_FIELD(rounding_method)
124  .set_default("round")
125  .describe(
126  "indicates how to find the \"nearest\" pixel in nearest_neighbor method"
127  "Available options are round, floor, and ceil.");
128  TVM_ATTR_FIELD(cubic_alpha)
129  .set_default(-0.5)
130  .describe("Spline Coefficient for Bicubic Interpolation");
131  TVM_ATTR_FIELD(cubic_exclude)
132  .set_default(0)
133  .describe("Flag to exclude exterior of the image during bicubic interpolation");
134  TVM_ATTR_FIELD(extrapolation_value)
135  .set_default(0.0)
136  .describe("Value to return when roi is outside of the image");
137  TVM_ATTR_FIELD(out_dtype).set_default(NullValue<DataType>()).describe("Output data type.");
138  }
139 };
140 
142 struct Resize3DAttrs : public tvm::AttrsNode<Resize3DAttrs> {
145  std::string layout;
146  std::string method;
148  std::string rounding_method;
149  double cubic_alpha;
153 
154  TVM_DECLARE_ATTRS(Resize3DAttrs, "relay.attrs.Resize3DAttrs") {
155  TVM_ATTR_FIELD(size).set_default(NullValue<Array<IndexExpr>>()).describe("Output Size.");
156  TVM_ATTR_FIELD(roi)
157  .set_default(NullValue<Array<FloatImm>>())
158  .describe("Region of Interest for coordinate transformation mode 'tf_crop_and_resize'");
159  TVM_ATTR_FIELD(layout).set_default("NCDHW").describe(
160  "Dimension ordering of input data. Can be 'NCDHW', 'NDHWC', etc."
161  "'N', 'C', 'D', 'H', 'W' stands for batch, channel, depth, height, and width"
162  "dimensions respectively. Resize3d is applied on the 'D', 'H' and"
163  "'W' dimensions.");
164  TVM_ATTR_FIELD(method).set_default("linear").describe(
165  "Specify the mode to use for scaling."
166  "nearest_neighbor - Nearest Neighbor"
167  "linear - Trilinear Interpolation"
168  "cubic - Tricubic Interpolation");
169  TVM_ATTR_FIELD(coordinate_transformation_mode)
170  .set_default("half_pixel")
171  .describe(
172  "Describes how to transform the coordinate in the resized tensor"
173  "to the coordinate in the original tensor."
174  "Refer to the ONNX Resize operator specification for details"
175  "Available options are half_pixel, align_corners and asymmetric");
176  TVM_ATTR_FIELD(rounding_method)
177  .set_default("round")
178  .describe(
179  "indicates how to find the \"nearest\" pixel in nearest_neighbor method"
180  "Available options are round, floor, and ceil.");
181  TVM_ATTR_FIELD(cubic_alpha)
182  .set_default(-0.5)
183  .describe("Spline Coefficient for Tricubic Interpolation");
184  TVM_ATTR_FIELD(cubic_exclude)
185  .set_default(0)
186  .describe("Flag to exclude exterior of the image during tricubic interpolation");
187  TVM_ATTR_FIELD(extrapolation_value)
188  .set_default(0.0)
189  .describe("Value to return when roi is outside of the image");
190  TVM_ATTR_FIELD(out_dtype).set_default(NullValue<DataType>()).describe("Output data type.");
191  }
192 };
193 
195 struct CropAndResizeAttrs : public tvm::AttrsNode<CropAndResizeAttrs> {
197  std::string layout;
198  std::string method;
201 
202  TVM_DECLARE_ATTRS(CropAndResizeAttrs, "relay.attrs.CropAndResizeAttrs") {
203  TVM_ATTR_FIELD(crop_size).set_default(NullValue<Array<IndexExpr>>()).describe("Target Size.");
204  TVM_ATTR_FIELD(layout).set_default("NCHW").describe(
205  "Dimension ordering of input data. Can be 'NCHW', 'NHWC', etc."
206  "'N', 'C', 'H', 'W' stands for batch, channel, height, and width"
207  "dimensions respectively. Resize is applied on the 'H' and"
208  "'W' dimensions.");
209  TVM_ATTR_FIELD(method)
210  .set_default("bilinear")
211  .describe(
212  "Specify the mode to use for scaling."
213  "nearest_neighbor - Nearest Neighbor"
214  "bilinear - Bilinear Interpolation");
215  TVM_ATTR_FIELD(extrapolation_value)
216  .set_default(0.0)
217  .describe("Specify value for extrapolation.");
218  TVM_ATTR_FIELD(out_dtype).set_default(NullValue<DataType>()).describe("Output data type.");
219  }
220 };
221 
223 struct Dilation2DAttrs : public tvm::AttrsNode<Dilation2DAttrs> {
227  std::string data_layout;
228  std::string kernel_layout;
230 
231  TVM_DECLARE_ATTRS(Dilation2DAttrs, "relay.attrs.Dilation2DAttrs") {
232  TVM_ATTR_FIELD(strides)
233  .set_default(Array<IndexExpr>({1, 1}))
234  .describe("Specifies the strides of the sliding window. [stride_height, stride_width].");
235  TVM_ATTR_FIELD(padding)
236  .set_default(Array<IndexExpr>({0, 0}))
237  .describe(
238  "If padding is non-zero, then the input is implicitly zero-padded"
239  "Padding support both symmetric and asymmetric as"
240  "one int : same padding used on all sides"
241  "two int : bottom, right will use same padding as top, left"
242  "four int : padding width in the order of (top, left, bottom, right)");
243  TVM_ATTR_FIELD(dilations)
244  .set_default(Array<IndexExpr>({1, 1}))
245  .describe("Specifies the dilation rate to use. [dilation_height, dilation_width]");
246  TVM_ATTR_FIELD(data_layout)
247  .set_default("NCHW")
248  .describe(
249  "Dimension ordering of input data. Can be 'NCHW', 'NHWC', etc."
250  "'N', 'C', 'H', 'W' stands for batch, channel, height, and width"
251  "dimensions respectively. Convolution is applied on the 'H' and"
252  "'W' dimensions.");
253  TVM_ATTR_FIELD(kernel_layout)
254  .set_default("IHW")
255  .describe(
256  "Dimension ordering of weight. Can be 'IHW', 'HWI', etc."
257  "'I', 'H', 'W' stands for input_channel, height, and width"
258  "dimensions respectively.");
259  TVM_ATTR_FIELD(out_dtype)
260  .set_default(NullValue<DataType>())
261  .describe("Output data type, set to explicit type under mixed precision setting");
262  }
263 };
264 
266 struct AffineGridAttrs : public tvm::AttrsNode<AffineGridAttrs> {
268 
269  TVM_DECLARE_ATTRS(AffineGridAttrs, "relay.attrs.AffineGridAttrs") {
270  TVM_ATTR_FIELD(target_shape).describe("Specifies the output shape (H, W).");
271  }
272 };
273 
275 struct GridSampleAttrs : public tvm::AttrsNode<GridSampleAttrs> {
280 
281  TVM_DECLARE_ATTRS(GridSampleAttrs, "relay.attrs.GridSampleAttrs") {
282  TVM_ATTR_FIELD(method)
283  .set_default("bilinear")
284  .describe(
285  "Specify the mode to use for scaling."
286  "nearest - 2D or 3D Nearest Interpolation."
287  "bilinear - '2D Bilinear' or '3D Trilinear' Interpolation."
288  "bicubic - 2D Bicubic Interpolation.");
289  TVM_ATTR_FIELD(layout).set_default("NCHW").describe(
290  "Dimension ordering of input data. Can be 'NCHW', 'NCDHW', etc."
291  "'N', 'C', 'D', 'H', 'W' stands for batch, channel, depth, height, and width"
292  "dimensions respectively."
293  "2D Resize is applied on the 'H' and 'W' dimensions."
294  "3D Resize is applied on the 'D' and 'H' and 'W' dimensions.");
295  TVM_ATTR_FIELD(padding_mode)
296  .set_default("zeros")
297  .describe(
298  "If :attr:'grid' has values outside the range of '[-1, 1]', the corresponding"
299  "outputs are handled as defined by padding_mode. Options are"
300  "padding_mode='zeros': use '0' for out-of-bound grid locations,"
301  "padding_mode='border': use border values for out-of-bound grid locations"
302  "padding_mode='reflection': use values at locations reflected by"
303  "the border for out-of-bound grid locations. For location far away"
304  "from the border, it will keep being reflected until becoming in bound,"
305  "e.g., (normalized) pixel location 'x = -3.5' reflects by border '-1'"
306  "and becomes 'x' = 1.5, then reflects by border '1' and becomes"
307  "'x' = -0.5");
308  TVM_ATTR_FIELD(align_corners)
309  .set_default(true)
310  .describe(
311  "Geometrically, we consider the pixels of the"
312  "input as squares rather than points."
313  "If set to True, the extrema (-1 and 1) are considered as referring"
314  "to the center points of the input's corner pixels. If set to False, they"
315  "are instead considered as referring to the corner points of the input's corner"
316  "pixels, making the sampling more resolution agnostic.");
317  }
318 };
319 
320 } // namespace relay
321 } // namespace tvm
322 #endif // TVM_RELAY_ATTRS_IMAGE_H_
std::string rounding_method
Definition: image.h:95
TVM_DECLARE_ATTRS(CropAndResizeAttrs, "relay.attrs.CropAndResizeAttrs")
Definition: image.h:202
DataType out_dtype
Definition: image.h:152
DataType out_dtype
Definition: image.h:99
double cubic_alpha
Definition: image.h:149
TVM_DECLARE_ATTRS(Resize2DAttrs, "relay.attrs.Resize2DAttrs")
Definition: image.h:101
DataType out_dtype
Definition: image.h:46
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Array< IndexExpr > padding
Definition: image.h:225
Attributes used in dilation operators.
Definition: image.h:223
double extrapolation_value
Definition: image.h:98
Attributes used in image crop_and_resize operator.
Definition: image.h:195
double extrapolation_value
Definition: image.h:151
Array< IndexExpr > size
Definition: image.h:90
std::string data_layout
Definition: image.h:227
DataType out_dtype
Definition: image.h:200
Attributes used in image resize1d operator.
Definition: image.h:36
String layout
Definition: image.h:277
int cubic_exclude
Definition: image.h:97
TVM_DECLARE_ATTRS(Resize3DAttrs, "relay.attrs.Resize3DAttrs")
Definition: image.h:154
std::string rounding_method
Definition: image.h:148
Array< FloatImm > roi
Definition: image.h:91
double extrapolation_value
Definition: image.h:45
Helpers for attribute objects.
double cubic_alpha
Definition: image.h:96
Array< IndexExpr > target_shape
Definition: image.h:267
std::string layout
Definition: image.h:197
Array< IndexExpr > size
Definition: image.h:37
String padding_mode
Definition: image.h:278
std::string method
Definition: image.h:40
Attributes used in image affine_grid operator.
Definition: image.h:266
std::string kernel_layout
Definition: image.h:228
String method
Definition: image.h:276
TVM_DECLARE_ATTRS(GridSampleAttrs, "relay.attrs.GridSampleAttrs")
Definition: image.h:281
Runtime primitive data type.
Definition: data_type.h:41
DataType out_dtype
Definition: image.h:229
Array< IndexExpr > dilations
Definition: image.h:226
std::string layout
Definition: image.h:145
int cubic_exclude
Definition: image.h:150
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
std::string coordinate_transformation_mode
Definition: image.h:41
std::string layout
Definition: image.h:39
std::string method
Definition: image.h:146
#define TVM_ATTR_FIELD(FieldName)
Declare an attribute field.
Definition: attrs.h:76
Reference to string objects.
Definition: string.h:98
TVM_DECLARE_ATTRS(Resize1DAttrs, "relay.attrs.Resize1DAttrs")
Definition: image.h:48
int cubic_exclude
Definition: image.h:44
Attributes used in image resize2d operator.
Definition: image.h:89
double extrapolation_value
Definition: image.h:199
Array< IndexExpr > strides
Definition: image.h:224
Array< FloatImm > roi
Definition: image.h:38
DataType NullValue< DataType >()
Definition: attrs.h:90
Array< IndexExpr > size
Definition: image.h:143
std::string rounding_method
Definition: image.h:42
Attributes used in image grid_sample operator.
Definition: image.h:275
bool align_corners
Definition: image.h:279
The base class of the all the Use "curiously recurring template pattern".
Definition: attrs.h:834
std::string method
Definition: image.h:198
Base classes for the Relay IR.
Attributes used in image resize3d operator.
Definition: image.h:142
std::string method
Definition: image.h:93
double cubic_alpha
Definition: image.h:43
TObjectRef NullValue()
Create a NodeRef type that represents null.
Definition: attrs.h:84
TVM_DECLARE_ATTRS(Dilation2DAttrs, "relay.attrs.Dilation2DAttrs")
Definition: image.h:231
Array< IndexExpr > crop_size
Definition: image.h:196
std::string coordinate_transformation_mode
Definition: image.h:94
TVM_DECLARE_ATTRS(AffineGridAttrs, "relay.attrs.AffineGridAttrs")
Definition: image.h:269
std::string layout
Definition: image.h:92
Array< FloatImm > roi
Definition: image.h:144
std::string coordinate_transformation_mode
Definition: image.h:147