tvm
vision.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_VISION_H_
25 #define TVM_RELAY_ATTRS_VISION_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 MultiBoxPriorAttrs : public tvm::AttrsNode<MultiBoxPriorAttrs> {
41  bool clip;
42 
43  TVM_DECLARE_ATTRS(MultiBoxPriorAttrs, "relay.attrs.MultiBoxPriorAttrs") {
45  .set_default(Array<IndexExpr>({static_cast<float>(1.0)}))
46  .describe("List of sizes of generated MultiBoxPriores.");
48  .set_default(Array<IndexExpr>({static_cast<float>(1.0)}))
49  .describe("List of aspect ratios of generated MultiBoxPriores.");
51  .set_default(Array<IndexExpr>({static_cast<float>(-1.0), static_cast<float>(-1.0)}))
52  .describe("Priorbox step across y and x, -1 for auto calculation.");
54  .set_default(Array<IndexExpr>({static_cast<float>(0.5), static_cast<float>(0.5)}))
55  .describe("Priorbox center offsets, y and x respectively.");
56  TVM_ATTR_FIELD(clip).set_default(false).describe("Whether to clip out-of-boundary boxes.");
57  }
58 };
59 
60 struct MultiBoxTransformLocAttrs : public tvm::AttrsNode<MultiBoxTransformLocAttrs> {
61  bool clip;
62  double threshold;
65 
66  TVM_DECLARE_ATTRS(MultiBoxTransformLocAttrs, "relay.attrs.MultiBoxTransformLocAttrs") {
67  TVM_ATTR_FIELD(clip).set_default(true).describe("Clip out-of-boundary boxes.");
68  TVM_ATTR_FIELD(threshold).set_default(0.01).describe("Threshold to be a positive prediction.");
70  .set_default(Array<IndexExpr>({0.1f, 0.1f, 0.2f, 0.2f}))
71  .describe("Variances to be decoded from box regression output.");
73  .set_default(false)
74  .describe("Whether to keep boxes detected as background or not");
75  }
76 };
77 
79 struct GetValidCountsAttrs : public tvm::AttrsNode<GetValidCountsAttrs> {
81  int id_index;
83 
84  TVM_DECLARE_ATTRS(GetValidCountsAttrs, "relay.attrs.GetValidCountsAttrs") {
85  TVM_ATTR_FIELD(score_threshold).describe("Lower limit of score for valid bounding boxes.");
86  TVM_ATTR_FIELD(id_index).set_default(0).describe("Axis index of id.");
87  TVM_ATTR_FIELD(score_index).set_default(1).describe("Index of the scores/confidence of boxes.");
88  }
89 };
90 
92 struct NonMaximumSuppressionAttrs : public tvm::AttrsNode<NonMaximumSuppressionAttrs> {
94  int top_k;
97  int id_index;
100 
101  TVM_DECLARE_ATTRS(NonMaximumSuppressionAttrs, "relay.attrs.NonMaximumSuppressionAttrs") {
103  .set_default(false)
104  .describe("Suppress all detections regardless of class_id.");
105  TVM_ATTR_FIELD(top_k).set_default(-1).describe(
106  "Keep maximum top k detections before nms, -1 for no limit.");
108  .set_default(2)
109  .describe("Start index of the consecutive 4 coordinates.");
110  TVM_ATTR_FIELD(score_index).set_default(1).describe("Index of the scores/confidence of boxes.");
111  TVM_ATTR_FIELD(id_index).set_default(0).describe("Axis index of id.");
113  .set_default(true)
114  .describe("Whether to return box indices in input data.");
116  .set_default(false)
117  .describe("Whether to move all invalid bounding boxes to the bottom.");
118  }
119 };
120 
123  : public tvm::AttrsNode<AllClassNonMaximumSuppressionAttrs> {
124  std::string output_format;
125 
127  "relay.attrs.AllClassNonMaximumSuppressionAttrs") {
129  .set_default("onnx")
130  .describe(
131  "Output format, onnx or tensorflow. Returns outputs in a way that can be easily "
132  "consumed by each frontend.");
133  }
134 };
135 
138  : public tvm::AttrsNode<RegularNonMaximumSuppressionAttrs> {
140  int32_t max_detections;
141  int32_t num_classes;
144 
146  "relay.attrs.RegularNonMaximumSuppressionAttrs") {
148  .describe("The maxinum number of output selected boxes per class.");
149  TVM_ATTR_FIELD(max_detections).describe("The maxinum number of output selected boxes.");
150  TVM_ATTR_FIELD(num_classes).describe("The number of classes without background.");
151  TVM_ATTR_FIELD(iou_threshold).describe("The IoU threshold for box the overlap test.");
153  .describe("Score threshold to filter out low score boxes early.");
154  }
155 };
156 
158 struct ROIAlignAttrs : public tvm::AttrsNode<ROIAlignAttrs> {
162  std::string layout;
163  std::string mode;
164  TVM_DECLARE_ATTRS(ROIAlignAttrs, "relay.attrs.ROIAlignAttrs") {
165  TVM_ATTR_FIELD(pooled_size).describe("Output size of roi align.");
167  .describe(
168  "Ratio of input feature map height (or w) to raw image height (or w). "
169  "Equals the reciprocal of total stride in convolutional layers, which should be "
170  "in range (0.0, 1.0]");
172  .set_default(-1)
173  .describe("Optional sampling ratio of ROI align, using adaptive size by default.");
174  TVM_ATTR_FIELD(layout).set_default("NCHW").describe(
175  "Dimension ordering of data and weight. Can be 'NCHW', 'NHWC', etc."
176  "'N', 'C', 'H', 'W' stands for batch, channel, height, and width"
177  "dimensions respectively. Convolution is applied on the 'H' and"
178  "'W' dimensions.");
179  TVM_ATTR_FIELD(mode).set_default("avg").describe(
180  "Mode for ROI Align. Can be 'avg' or 'max'. The default mode is 'avg'.");
181  }
182 };
183 
185 struct ROIPoolAttrs : public tvm::AttrsNode<ROIPoolAttrs> {
188  std::string layout;
189  TVM_DECLARE_ATTRS(ROIPoolAttrs, "relay.attrs.ROIPoolAttrs") {
190  TVM_ATTR_FIELD(pooled_size).describe("Output size of roi pool.");
192  .describe(
193  "Ratio of input feature map height (or w) to raw image height (or w). "
194  "Equals the reciprocal of total stride in convolutional layers, which should be "
195  "in range (0.0, 1.0]");
196  TVM_ATTR_FIELD(layout).set_default("NCHW").describe(
197  "Dimension ordering of data and weight. Can be 'NCHW', 'NHWC', etc."
198  "'N', 'C', 'H', 'W' stands for batch, channel, height, and width"
199  "dimensions respectively. Convolution is applied on the 'H' and"
200  "'W' dimensions.");
201  }
202 };
203 
205 struct YoloReorgAttrs : public tvm::AttrsNode<YoloReorgAttrs> {
207 
208  TVM_DECLARE_ATTRS(YoloReorgAttrs, "relay.attrs.YoloReorgAttrs") {
209  TVM_ATTR_FIELD(stride).set_default(1).describe("Stride value for yolo reorg");
210  }
211 };
212 
214 struct ProposalAttrs : public tvm::AttrsNode<ProposalAttrs> {
218  double threshold;
222  bool iou_loss;
223 
224  TVM_DECLARE_ATTRS(ProposalAttrs, "relay.attrs.ProposalAttrs") {
226  .set_default(Array<IndexExpr>({4.0f, 8.0f, 16.0f, 32.0f}))
227  .describe("Used to generate anchor windows by enumerating scales");
229  .set_default(Array<IndexExpr>({0.5f, 1.0f, 2.0f}))
230  .describe("Used to generate anchor windows by enumerating ratios");
232  .set_default(16)
233  .describe(
234  "The size of the receptive field each unit in the convolution layer of the rpn,"
235  "for example the product of all stride's prior to this layer.");
236  TVM_ATTR_FIELD(threshold).set_default(0.7).describe(
237  "IoU threshold of non-maximum suppresion (suppress boxes with IoU >= this threshold)");
239  .set_default(6000)
240  .describe("Number of top scoring boxes to apply NMS. -1 to use all boxes");
242  .set_default(300)
243  .describe("Number of top scoring boxes to keep after applying NMS to RPN proposals");
244  TVM_ATTR_FIELD(rpn_min_size).set_default(16).describe("Minimum height or width in proposal");
245  TVM_ATTR_FIELD(iou_loss).set_default(false).describe("Usage of IoU Loss");
246  }
247 };
248 
249 } // namespace relay
250 } // namespace tvm
251 #endif // TVM_RELAY_ATTRS_VISION_H_
The base class of the all the Use "curiously recurring template pattern".
Definition: attrs.h:870
Container of constant int that adds more constructors.
Definition: expr.h:632
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Helpers for attribute objects.
#define TVM_ATTR_FIELD(FieldName)
Declare an attribute field.
Definition: attrs.h:76
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Base classes for the Relay IR.
Attributes used in all_class_non_maximum_suppression operator.
Definition: vision.h:123
TVM_DECLARE_ATTRS(AllClassNonMaximumSuppressionAttrs, "relay.attrs.AllClassNonMaximumSuppressionAttrs")
Definition: vision.h:126
std::string output_format
Definition: vision.h:124
Attributes used in get_valid_counts operator.
Definition: vision.h:79
TVM_DECLARE_ATTRS(GetValidCountsAttrs, "relay.attrs.GetValidCountsAttrs")
Definition: vision.h:84
int score_index
Definition: vision.h:82
int id_index
Definition: vision.h:81
Optional< FloatImm > score_threshold
Definition: vision.h:80
Attributes used in multibox_prior operators.
Definition: vision.h:36
Array< IndexExpr > steps
Definition: vision.h:39
Array< IndexExpr > offsets
Definition: vision.h:40
TVM_DECLARE_ATTRS(MultiBoxPriorAttrs, "relay.attrs.MultiBoxPriorAttrs")
Definition: vision.h:43
bool clip
Definition: vision.h:41
Array< IndexExpr > sizes
Definition: vision.h:37
Array< IndexExpr > ratios
Definition: vision.h:38
Array< IndexExpr > variances
Definition: vision.h:63
bool keep_background
Definition: vision.h:64
bool clip
Definition: vision.h:61
double threshold
Definition: vision.h:62
TVM_DECLARE_ATTRS(MultiBoxTransformLocAttrs, "relay.attrs.MultiBoxTransformLocAttrs")
Definition: vision.h:66
Attributes used in non_maximum_suppression operator.
Definition: vision.h:92
int coord_start
Definition: vision.h:95
int id_index
Definition: vision.h:97
bool invalid_to_bottom
Definition: vision.h:99
bool return_indices
Definition: vision.h:98
TVM_DECLARE_ATTRS(NonMaximumSuppressionAttrs, "relay.attrs.NonMaximumSuppressionAttrs")
Definition: vision.h:101
int top_k
Definition: vision.h:94
int score_index
Definition: vision.h:96
bool force_suppress
Definition: vision.h:93
Attributes used in proposal operators.
Definition: vision.h:214
bool iou_loss
Definition: vision.h:222
Array< IndexExpr > scales
Definition: vision.h:215
int feature_stride
Definition: vision.h:217
int rpn_pre_nms_top_n
Definition: vision.h:219
TVM_DECLARE_ATTRS(ProposalAttrs, "relay.attrs.ProposalAttrs")
Definition: vision.h:224
int rpn_min_size
Definition: vision.h:221
Array< IndexExpr > ratios
Definition: vision.h:216
double threshold
Definition: vision.h:218
int rpn_post_nms_top_n
Definition: vision.h:220
Attributes used in roi_align operators.
Definition: vision.h:158
double spatial_scale
Definition: vision.h:160
std::string layout
Definition: vision.h:162
TVM_DECLARE_ATTRS(ROIAlignAttrs, "relay.attrs.ROIAlignAttrs")
Definition: vision.h:164
int sample_ratio
Definition: vision.h:161
std::string mode
Definition: vision.h:163
Array< IndexExpr > pooled_size
Definition: vision.h:159
Attributes used in roi_pool operators.
Definition: vision.h:185
Array< IndexExpr > pooled_size
Definition: vision.h:186
TVM_DECLARE_ATTRS(ROIPoolAttrs, "relay.attrs.ROIPoolAttrs")
Definition: vision.h:189
std::string layout
Definition: vision.h:188
double spatial_scale
Definition: vision.h:187
Attributes used in regular_non_maximum_suppression operator.
Definition: vision.h:138
int32_t max_detections
Definition: vision.h:140
int32_t num_classes
Definition: vision.h:141
TVM_DECLARE_ATTRS(RegularNonMaximumSuppressionAttrs, "relay.attrs.RegularNonMaximumSuppressionAttrs")
Definition: vision.h:145
int32_t max_detections_per_class
Definition: vision.h:139
double score_threshold
Definition: vision.h:143
double iou_threshold
Definition: vision.h:142
Attributes used in yolo reorg operators.
Definition: vision.h:205
Integer stride
Definition: vision.h:206
TVM_DECLARE_ATTRS(YoloReorgAttrs, "relay.attrs.YoloReorgAttrs")
Definition: vision.h:208