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  */
23 #ifndef TVM_RELAX_ATTRS_VISION_H_
24 #define TVM_RELAX_ATTRS_VISION_H_
25 
26 #include <tvm/ffi/string.h>
27 #include <tvm/ir/attrs.h>
28 #include <tvm/ir/type.h>
29 #include <tvm/relax/expr.h>
30 #include <tvm/runtime/object.h>
31 
32 namespace tvm {
33 namespace relax {
34 
37  : public AttrsNodeReflAdapter<AllClassNonMaximumSuppressionAttrs> {
38  ffi::String output_format;
39 
40  static void RegisterReflection() {
41  namespace refl = tvm::ffi::reflection;
42  refl::ObjectDef<AllClassNonMaximumSuppressionAttrs>().def_ro(
44  "Output format, onnx or tensorflow. Returns outputs in a way that can be easily "
45  "consumed by each frontend.");
46  }
47  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.AllClassNonMaximumSuppressionAttrs",
49 }; // struct AllClassNonMaximumSuppressionAttrs
50 
52 struct ROIAlignAttrs : public AttrsNodeReflAdapter<ROIAlignAttrs> {
53  ffi::Array<int64_t> pooled_size;
54  double spatial_scale;
56  bool aligned;
57  ffi::String layout;
58  ffi::String mode;
59 
60  static void RegisterReflection() {
61  namespace refl = tvm::ffi::reflection;
62  refl::ObjectDef<ROIAlignAttrs>()
63  .def_ro("pooled_size", &ROIAlignAttrs::pooled_size, "Output size of roi align.")
64  .def_ro("spatial_scale", &ROIAlignAttrs::spatial_scale,
65  "Ratio of input feature map height (or width) to raw image height (or width).")
66  .def_ro("sample_ratio", &ROIAlignAttrs::sample_ratio,
67  "Optional sampling ratio of ROI align, using adaptive size by default.")
68  .def_ro("aligned", &ROIAlignAttrs::aligned,
69  "Whether to use the aligned ROIAlign semantics without the legacy 1-pixel clamp.")
70  .def_ro("layout", &ROIAlignAttrs::layout, "Dimension ordering of the input data.")
71  .def_ro("mode", &ROIAlignAttrs::mode, "Mode for ROI Align. Can be 'avg' or 'max'.");
72  }
74 }; // struct ROIAlignAttrs
75 
77 struct ROIPoolAttrs : public AttrsNodeReflAdapter<ROIPoolAttrs> {
78  ffi::Array<int64_t> pooled_size;
79  double spatial_scale;
80  ffi::String layout;
81 
82  static void RegisterReflection() {
83  namespace refl = tvm::ffi::reflection;
84  refl::ObjectDef<ROIPoolAttrs>()
85  .def_ro("pooled_size", &ROIPoolAttrs::pooled_size, "Output size of roi pool.")
86  .def_ro("spatial_scale", &ROIPoolAttrs::spatial_scale,
87  "Ratio of input feature map height (or width) to raw image height (or width).")
88  .def_ro("layout", &ROIPoolAttrs::layout, "Dimension ordering of the input data.");
89  }
91 }; // struct ROIPoolAttrs
92 
94 struct GetValidCountsAttrs : public AttrsNodeReflAdapter<GetValidCountsAttrs> {
96  int id_index;
98 
99  static void RegisterReflection() {
100  namespace refl = tvm::ffi::reflection;
101  refl::ObjectDef<GetValidCountsAttrs>()
102  .def_ro("score_threshold", &GetValidCountsAttrs::score_threshold,
103  "Lower limit of score for valid bounding boxes.")
104  .def_ro("id_index", &GetValidCountsAttrs::id_index,
105  "Index of the class categories, -1 to disable.")
106  .def_ro("score_index", &GetValidCountsAttrs::score_index,
107  "Index of the scores/confidence of boxes.");
108  }
109  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.GetValidCountsAttrs", GetValidCountsAttrs,
110  BaseAttrsNode);
111 }; // struct GetValidCountsAttrs
112 
115  : public AttrsNodeReflAdapter<NonMaximumSuppressionAttrs> {
119  int top_k;
122  int id_index;
125 
126  static void RegisterReflection() {
127  namespace refl = tvm::ffi::reflection;
128  refl::ObjectDef<NonMaximumSuppressionAttrs>()
129  .def_ro("max_output_size", &NonMaximumSuppressionAttrs::max_output_size,
130  "Max number of output valid boxes, -1 for no limit.")
131  .def_ro("iou_threshold", &NonMaximumSuppressionAttrs::iou_threshold,
132  "Non-maximum suppression IoU threshold.")
133  .def_ro("force_suppress", &NonMaximumSuppressionAttrs::force_suppress,
134  "Whether to suppress all detections regardless of class_id.")
135  .def_ro("top_k", &NonMaximumSuppressionAttrs::top_k,
136  "Keep maximum top k detections before nms, -1 for no limit.")
137  .def_ro("coord_start", &NonMaximumSuppressionAttrs::coord_start,
138  "Start index of the consecutive 4 coordinates.")
139  .def_ro("score_index", &NonMaximumSuppressionAttrs::score_index,
140  "Index of the scores/confidence of boxes.")
141  .def_ro("id_index", &NonMaximumSuppressionAttrs::id_index,
142  "Index of the class categories, -1 to disable.")
143  .def_ro("return_indices", &NonMaximumSuppressionAttrs::return_indices,
144  "Whether to return box indices in input data.")
145  .def_ro("invalid_to_bottom", &NonMaximumSuppressionAttrs::invalid_to_bottom,
146  "Whether to move all valid bounding boxes to the top.");
147  }
148  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.NonMaximumSuppressionAttrs",
150 }; // struct NonMaximumSuppressionAttrs
151 
153 struct MultiboxTransformLocAttrs : public AttrsNodeReflAdapter<MultiboxTransformLocAttrs> {
154  bool clip;
155  double threshold;
156  ffi::Array<double> variances;
158 
159  static void RegisterReflection() {
160  namespace refl = tvm::ffi::reflection;
161  refl::ObjectDef<MultiboxTransformLocAttrs>()
162  .def_ro("clip", &MultiboxTransformLocAttrs::clip,
163  "Clip decoded ymin,xmin,ymax,xmax to [0,1].")
164  .def_ro("threshold", &MultiboxTransformLocAttrs::threshold,
165  "After softmax, zero scores strictly below this value.")
166  .def_ro("variances", &MultiboxTransformLocAttrs::variances,
167  "(x,y,w,h) scales = TFLite 1/x_scale,1/y_scale,1/w_scale,1/h_scale on "
168  "encodings. Very large w/h scales can overflow exp in decode.")
169  .def_ro("keep_background", &MultiboxTransformLocAttrs::keep_background,
170  "If false, force output scores[:,0,:] to 0 (background class).");
171  }
172  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.MultiboxTransformLocAttrs",
174 }; // struct MultiboxTransformLocAttrs
175 
176 } // namespace relax
177 } // namespace tvm
178 
179 #endif // TVM_RELAX_ATTRS_VISION_H_
Helpers for attribute objects.
Adapter for AttrsNode with the new reflection API.
Definition: attrs.h:384
Base class of all attribute class.
Definition: attrs.h:101
IR/AST nodes for the unified type system in TVM.
Definition: repr_printer.h:91
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:37
A managed object in the TVM runtime.
Attributes used in AllClassNonMaximumSuppression operator.
Definition: vision.h:37
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.AllClassNonMaximumSuppressionAttrs", AllClassNonMaximumSuppressionAttrs, BaseAttrsNode)
static void RegisterReflection()
Definition: vision.h:40
ffi::String output_format
Definition: vision.h:38
Attributes used in GetValidCounts operator.
Definition: vision.h:94
int id_index
Definition: vision.h:96
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.GetValidCountsAttrs", GetValidCountsAttrs, BaseAttrsNode)
static void RegisterReflection()
Definition: vision.h:99
int score_index
Definition: vision.h:97
double score_threshold
Definition: vision.h:95
Attributes for multibox_transform_loc (SSD / TFLite-style box decode).
Definition: vision.h:153
static void RegisterReflection()
Definition: vision.h:159
bool clip
Definition: vision.h:154
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.MultiboxTransformLocAttrs", MultiboxTransformLocAttrs, BaseAttrsNode)
ffi::Array< double > variances
Definition: vision.h:156
double threshold
Definition: vision.h:155
bool keep_background
Definition: vision.h:157
Attributes used in NonMaximumSuppression operator.
Definition: vision.h:115
bool return_indices
Definition: vision.h:123
bool force_suppress
Definition: vision.h:118
int score_index
Definition: vision.h:121
double iou_threshold
Definition: vision.h:117
int top_k
Definition: vision.h:119
int id_index
Definition: vision.h:122
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.NonMaximumSuppressionAttrs", NonMaximumSuppressionAttrs, BaseAttrsNode)
static void RegisterReflection()
Definition: vision.h:126
int max_output_size
Definition: vision.h:116
bool invalid_to_bottom
Definition: vision.h:124
int coord_start
Definition: vision.h:120
Attributes used in ROIAlign operator.
Definition: vision.h:52
static void RegisterReflection()
Definition: vision.h:60
ffi::String layout
Definition: vision.h:57
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ROIAlignAttrs", ROIAlignAttrs, BaseAttrsNode)
bool aligned
Definition: vision.h:56
double spatial_scale
Definition: vision.h:54
ffi::String mode
Definition: vision.h:58
int sample_ratio
Definition: vision.h:55
ffi::Array< int64_t > pooled_size
Definition: vision.h:53
Attributes used in ROIPool operator.
Definition: vision.h:77
ffi::String layout
Definition: vision.h:80
static void RegisterReflection()
Definition: vision.h:82
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ROIPoolAttrs", ROIPoolAttrs, BaseAttrsNode)
double spatial_scale
Definition: vision.h:79
ffi::Array< int64_t > pooled_size
Definition: vision.h:78