tvm
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> {
38  std::string layout;
39  std::string method;
41  std::string rounding_method;
42  double cubic_alpha;
45 
46  TVM_DECLARE_ATTRS(Resize1DAttrs, "relay.attrs.Resize1DAttrs") {
47  TVM_ATTR_FIELD(size).set_default(NullValue<Array<IndexExpr> >()).describe("Output Size.");
48  TVM_ATTR_FIELD(layout).set_default("NCW").describe(
49  "Dimension ordering of input data. Can be 'NCW', 'NWC', etc."
50  "'N', 'C', 'W' stands for batch, channel and width"
51  "dimensions respectively. Resize is applied on the"
52  "'W' dimension.");
53  TVM_ATTR_FIELD(method).set_default("linear").describe(
54  "Specify the mode to use for scaling."
55  "nearest_neighbor - Nearest Neighbor"
56  "linear - Linear Interpolation"
57  "cubic - Cubic Interpolation");
58  TVM_ATTR_FIELD(coordinate_transformation_mode)
59  .set_default("half_pixel")
60  .describe(
61  "Describes how to transform the coordinate in the resized tensor"
62  "to the coordinate in the original tensor."
63  "Refer to the ONNX Resize operator specification for details"
64  "Available options are half_pixel, align_corners and asymmetric");
65  TVM_ATTR_FIELD(rounding_method)
66  .set_default("round")
67  .describe(
68  "indicates how to find the \"nearest\" pixel in nearest_neighbor method"
69  "Available options are round, floor, and ceil.");
70  TVM_ATTR_FIELD(cubic_alpha)
71  .set_default(-0.5)
72  .describe("Spline Coefficient for cubic interpolation");
73  TVM_ATTR_FIELD(cubic_exclude)
74  .set_default(0)
75  .describe("Flag to exclude exterior of the image during cubic interpolation");
76  TVM_ATTR_FIELD(out_dtype).set_default(NullValue<DataType>()).describe("Output data type.");
77  }
78 };
79 
81 struct Resize2DAttrs : public tvm::AttrsNode<Resize2DAttrs> {
83  std::string layout;
84  std::string method;
86  std::string rounding_method;
87  double cubic_alpha;
90 
91  TVM_DECLARE_ATTRS(Resize2DAttrs, "relay.attrs.Resize2DAttrs") {
92  TVM_ATTR_FIELD(size).set_default(NullValue<Array<IndexExpr> >()).describe("Output Size.");
93  TVM_ATTR_FIELD(layout).set_default("NCHW").describe(
94  "Dimension ordering of input data. Can be 'NCHW', 'NHWC', etc."
95  "'N', 'C', 'H', 'W' stands for batch, channel, height, and width"
96  "dimensions respectively. Resize is applied on the 'H' and"
97  "'W' dimensions.");
98  TVM_ATTR_FIELD(method).set_default("linear").describe(
99  "Specify the mode to use for scaling."
100  "nearest_neighbor - Nearest Neighbor"
101  "linear - Bilinear Interpolation"
102  "cubic - Bicubic Interpolation");
103  TVM_ATTR_FIELD(coordinate_transformation_mode)
104  .set_default("half_pixel")
105  .describe(
106  "Describes how to transform the coordinate in the resized tensor"
107  "to the coordinate in the original tensor."
108  "Refer to the ONNX Resize operator specification for details"
109  "Available options are half_pixel, align_corners and asymmetric");
110  TVM_ATTR_FIELD(rounding_method)
111  .set_default("round")
112  .describe(
113  "indicates how to find the \"nearest\" pixel in nearest_neighbor method"
114  "Available options are round, floor, and ceil.");
115  TVM_ATTR_FIELD(cubic_alpha)
116  .set_default(-0.5)
117  .describe("Spline Coefficient for Bicubic Interpolation");
118  TVM_ATTR_FIELD(cubic_exclude)
119  .set_default(0)
120  .describe("Flag to exclude exterior of the image during bicubic interpolation");
121  TVM_ATTR_FIELD(out_dtype).set_default(NullValue<DataType>()).describe("Output data type.");
122  }
123 };
124 
126 struct Resize3DAttrs : public tvm::AttrsNode<Resize3DAttrs> {
128  std::string layout;
129  std::string method;
131  std::string rounding_method;
132  double cubic_alpha;
135 
136  TVM_DECLARE_ATTRS(Resize3DAttrs, "relay.attrs.Resize3DAttrs") {
137  TVM_ATTR_FIELD(size).set_default(NullValue<Array<IndexExpr> >()).describe("Output Size.");
138  TVM_ATTR_FIELD(layout).set_default("NCDHW").describe(
139  "Dimension ordering of input data. Can be 'NCDHW', 'NDHWC', etc."
140  "'N', 'C', 'D', 'H', 'W' stands for batch, channel, depth, height, and width"
141  "dimensions respectively. Resize3d is applied on the 'D', 'H' and"
142  "'W' dimensions.");
143  TVM_ATTR_FIELD(method).set_default("linear").describe(
144  "Specify the mode to use for scaling."
145  "nearest_neighbor - Nearest Neighbor"
146  "linear - Trilinear Interpolation"
147  "cubic - Tricubic Interpolation");
148  TVM_ATTR_FIELD(coordinate_transformation_mode)
149  .set_default("half_pixel")
150  .describe(
151  "Describes how to transform the coordinate in the resized tensor"
152  "to the coordinate in the original tensor."
153  "Refer to the ONNX Resize operator specification for details"
154  "Available options are half_pixel, align_corners and asymmetric");
155  TVM_ATTR_FIELD(rounding_method)
156  .set_default("round")
157  .describe(
158  "indicates how to find the \"nearest\" pixel in nearest_neighbor method"
159  "Available options are round, floor, and ceil.");
160  TVM_ATTR_FIELD(cubic_alpha)
161  .set_default(-0.5)
162  .describe("Spline Coefficient for Tricubic Interpolation");
163  TVM_ATTR_FIELD(cubic_exclude)
164  .set_default(0)
165  .describe("Flag to exclude exterior of the image during tricubic interpolation");
166  TVM_ATTR_FIELD(out_dtype).set_default(NullValue<DataType>()).describe("Output data type.");
167  }
168 };
169 
171 struct CropAndResizeAttrs : public tvm::AttrsNode<CropAndResizeAttrs> {
173  std::string layout;
174  std::string method;
177 
178  TVM_DECLARE_ATTRS(CropAndResizeAttrs, "relay.attrs.CropAndResizeAttrs") {
179  TVM_ATTR_FIELD(crop_size).set_default(NullValue<Array<IndexExpr> >()).describe("Target Size.");
180  TVM_ATTR_FIELD(layout).set_default("NCHW").describe(
181  "Dimension ordering of input data. Can be 'NCHW', 'NHWC', etc."
182  "'N', 'C', 'H', 'W' stands for batch, channel, height, and width"
183  "dimensions respectively. Resize is applied on the 'H' and"
184  "'W' dimensions.");
185  TVM_ATTR_FIELD(method)
186  .set_default("bilinear")
187  .describe(
188  "Specify the mode to use for scaling."
189  "nearest_neighbor - Nearest Neighbor"
190  "bilinear - Bilinear Interpolation");
191  TVM_ATTR_FIELD(extrapolation_value)
192  .set_default(0.0)
193  .describe("Specify value for extrapolation.");
194  TVM_ATTR_FIELD(out_dtype).set_default(NullValue<DataType>()).describe("Output data type.");
195  }
196 };
197 
199 struct Dilation2DAttrs : public tvm::AttrsNode<Dilation2DAttrs> {
203  std::string data_layout;
204  std::string kernel_layout;
206 
207  TVM_DECLARE_ATTRS(Dilation2DAttrs, "relay.attrs.Dilation2DAttrs") {
208  TVM_ATTR_FIELD(strides)
209  .set_default(Array<IndexExpr>({1, 1}))
210  .describe("Specifies the strides of the sliding window. [stride_height, stride_width].");
211  TVM_ATTR_FIELD(padding)
212  .set_default(Array<IndexExpr>({0, 0}))
213  .describe(
214  "If padding is non-zero, then the input is implicitly zero-padded"
215  "Padding support both symmetric and asymmetric as"
216  "one int : same padding used on all sides"
217  "two int : bottom, right will use same padding as top, left"
218  "four int : padding width in the order of (top, left, bottom, right)");
219  TVM_ATTR_FIELD(dilations)
220  .set_default(Array<IndexExpr>({1, 1}))
221  .describe("Specifies the dilation rate to use. [dilation_height, dilation_width]");
222  TVM_ATTR_FIELD(data_layout)
223  .set_default("NCHW")
224  .describe(
225  "Dimension ordering of input data. Can be 'NCHW', 'NHWC', etc."
226  "'N', 'C', 'H', 'W' stands for batch, channel, height, and width"
227  "dimensions respectively. Convolution is applied on the 'H' and"
228  "'W' dimensions.");
229  TVM_ATTR_FIELD(kernel_layout)
230  .set_default("IHW")
231  .describe(
232  "Dimension ordering of weight. Can be 'IHW', 'HWI', etc."
233  "'I', 'H', 'W' stands for input_channel, height, and width"
234  "dimensions respectively.");
235  TVM_ATTR_FIELD(out_dtype)
236  .set_default(NullValue<DataType>())
237  .describe("Output data type, set to explicit type under mixed precision setting");
238  }
239 };
240 
242 struct AffineGridAttrs : public tvm::AttrsNode<AffineGridAttrs> {
244 
245  TVM_DECLARE_ATTRS(AffineGridAttrs, "relay.attrs.AffineGridAttrs") {
246  TVM_ATTR_FIELD(target_shape).describe("Specifies the output shape (H, W).");
247  }
248 };
249 
251 struct GridSampleAttrs : public tvm::AttrsNode<GridSampleAttrs> {
254 
255  TVM_DECLARE_ATTRS(GridSampleAttrs, "relay.attrs.GridSampleAttrs") {
256  TVM_ATTR_FIELD(method)
257  .set_default("bilinear")
258  .describe(
259  "Specify the mode to use for scaling."
260  "bilinear - Bilinear Interpolation");
261  TVM_ATTR_FIELD(layout).set_default("NCHW").describe(
262  "Dimension ordering of input data. Can be 'NCHW', 'NHWC', etc."
263  "'N', 'C', 'H', 'W' stands for batch, channel, height, and width"
264  "dimensions respectively. Resize is applied on the 'H' and"
265  "'W' dimensions.");
266  }
267 };
268 
269 } // namespace relay
270 } // namespace tvm
271 #endif // TVM_RELAY_ATTRS_IMAGE_H_
std::string rounding_method
Definition: image.h:86
TVM_DECLARE_ATTRS(CropAndResizeAttrs, "relay.attrs.CropAndResizeAttrs")
Definition: image.h:178
DataType out_dtype
Definition: image.h:134
DataType out_dtype
Definition: image.h:89
double cubic_alpha
Definition: image.h:132
TVM_DECLARE_ATTRS(Resize2DAttrs, "relay.attrs.Resize2DAttrs")
Definition: image.h:91
DataType out_dtype
Definition: image.h:44
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:36
Array< IndexExpr > padding
Definition: image.h:201
Attributes used in dilation operators.
Definition: image.h:199
Attributes used in image crop_and_resize operator.
Definition: image.h:171
Array< IndexExpr > size
Definition: image.h:82
std::string data_layout
Definition: image.h:203
DataType out_dtype
Definition: image.h:176
Attributes used in image resize1d operator.
Definition: image.h:36
String layout
Definition: image.h:253
int cubic_exclude
Definition: image.h:88
TVM_DECLARE_ATTRS(Resize3DAttrs, "relay.attrs.Resize3DAttrs")
Definition: image.h:136
std::string rounding_method
Definition: image.h:131
Helpers for attribute objects.
double cubic_alpha
Definition: image.h:87
Array< IndexExpr > target_shape
Definition: image.h:243
std::string layout
Definition: image.h:173
Array< IndexExpr > size
Definition: image.h:37
std::string method
Definition: image.h:39
Attributes used in image affine_grid operator.
Definition: image.h:242
std::string kernel_layout
Definition: image.h:204
String method
Definition: image.h:252
TVM_DECLARE_ATTRS(GridSampleAttrs, "relay.attrs.GridSampleAttrs")
Definition: image.h:255
Runtime primitive data type.
Definition: data_type.h:41
DataType out_dtype
Definition: image.h:205
Array< IndexExpr > dilations
Definition: image.h:202
std::string layout
Definition: image.h:128
int cubic_exclude
Definition: image.h:133
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:270
std::string coordinate_transformation_mode
Definition: image.h:40
std::string layout
Definition: image.h:38
std::string method
Definition: image.h:129
#define TVM_ATTR_FIELD(FieldName)
Declare an attribute field.
Definition: attrs.h:76
Reference to string objects.
Definition: string.h:129
TVM_DECLARE_ATTRS(Resize1DAttrs, "relay.attrs.Resize1DAttrs")
Definition: image.h:46
int cubic_exclude
Definition: image.h:43
Attributes used in image resize2d operator.
Definition: image.h:81
double extrapolation_value
Definition: image.h:175
Array< IndexExpr > strides
Definition: image.h:200
DataType NullValue< DataType >()
Definition: attrs.h:90
Array< IndexExpr > size
Definition: image.h:127
std::string rounding_method
Definition: image.h:41
Attributes used in image grid_sample operator.
Definition: image.h:251
The base class of the all the Use "curiously recurring template pattern".
Definition: attrs.h:793
std::string method
Definition: image.h:174
Base classes for the Relay IR.
Attributes used in image resize3d operator.
Definition: image.h:126
std::string method
Definition: image.h:84
double cubic_alpha
Definition: image.h:42
TObjectRef NullValue()
Create a NodeRef type that represents null.
Definition: attrs.h:84
TVM_DECLARE_ATTRS(Dilation2DAttrs, "relay.attrs.Dilation2DAttrs")
Definition: image.h:207
Array< IndexExpr > crop_size
Definition: image.h:172
std::string coordinate_transformation_mode
Definition: image.h:85
TVM_DECLARE_ATTRS(AffineGridAttrs, "relay.attrs.AffineGridAttrs")
Definition: image.h:245
std::string layout
Definition: image.h:83
std::string coordinate_transformation_mode
Definition: image.h:130