Skip to content

Commit ee7803e

Browse files
committed
Review comments
1 parent 07bbf70 commit ee7803e

File tree

4 files changed

+22
-105
lines changed

4 files changed

+22
-105
lines changed

docs/langref/relay_op.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ This level enables additional math and transform operators.
131131
:nosignatures:
132132

133133
tvm.relay.image.resize
134-
tvm.relay.vision.yolo_regorg
135-
tvm.relay.vision.yolo_region
136-
tvm.relay.vision.yolov3_yolo
134+
tvm.relay.vision.yolo_reorg
137135

138136

139137
**Level 10: Temporary Operators**
@@ -236,9 +234,7 @@ Level 4 Definitions
236234
Level 5 Definitions
237235
-------------------
238236
.. autofunction:: tvm.relay.image.resize
239-
autofunction:: tvm.relay.vision.yolo_regorg
240-
autofunction:: tvm.relay.vision.yolo_region
241-
autofunction:: tvm.relay.vision.yolov3_yolo
237+
autofunction:: tvm.relay.vision.yolo_reorg
242238

243239

244240
Level 10 Definitions

python/tvm/relay/op/vision/yolo.py

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
"""Yolo operations."""
22
from . import _make
33

4-
def yolo_reorg(data, stride=1):
5-
"""Yolo reorg operation. This layer reorganize the output based on the stride value.
6-
Its function is mostly shape transform.
4+
def yolo_reorg(data, stride):
5+
"""Yolo reorg operation used in darknet models.
6+
This layer shuffles the input tensor values based on the stride value.
7+
Along with the shuffling, it does the shape transform.
8+
If '(n, c, h, w)' is the data shape and 's' is stride, output shape is '(n, c*s*s, h/s, w/s)'
9+
Example: data(1, 4, 2, 2) = [[[[ 0 1] [ 2 3]]
10+
[[ 4 5] [ 6 7]]
11+
[[ 8 9] [10 11]]
12+
[[12 13] [14 15]]]]
13+
stride = 2
14+
ret(1, 16, 1, 1) = [[[[ 0]] [[ 2]] [[ 8]] [[10]]
15+
[[ 1]] [[ 3]] [[ 9]] [[11]]
16+
[[ 4]] [[ 6]] [[12]] [[14]]
17+
[[ 5]] [[ 7]] [[13]] [[15]]]]
18+
19+
Note: stride=1 has no significance for reorg operation.
720
821
Parameters
922
----------
@@ -19,35 +32,3 @@ def yolo_reorg(data, stride=1):
1932
The computed result.
2033
"""
2134
return _make.yolo_reorg(data, stride)
22-
23-
24-
def yolo_region(data):
25-
"""Yolo region operation used for detection.
26-
27-
Parameters
28-
----------
29-
data : relay.Expr
30-
The input data tensor.
31-
32-
Returns
33-
-------
34-
ret : relay.Expr
35-
The computed result.
36-
"""
37-
return _make.yolo_region(data)
38-
39-
40-
def yolov3_yolo(data):
41-
"""Yolo operation used for detection
42-
43-
Parameters
44-
----------
45-
data : relay.Expr
46-
The input data tensor.
47-
48-
Returns
49-
-------
50-
ret : relay.Expr
51-
The computed result.
52-
"""
53-
return _make.yolov3_yolo(data)

src/relay/op/vision/yolo.cc

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -65,47 +65,5 @@ Its function is mostly shape transform.")doc" TVM_ADD_FILELINE)
6565
.set_attrs_type_key("relay.attrs.YoloReorgAttrs")
6666
.add_type_rel("YoloReorg", YoloReorgRel);
6767

68-
69-
Expr MakeYoloRegion(Expr data) {
70-
static const Op& op = Op::Get("vision.yolo_region");
71-
return CallNode::make(op, {data}, Attrs(), {});
72-
}
73-
74-
75-
TVM_REGISTER_API("relay.op.vision._make.yolo_region")
76-
.set_body([](const TVMArgs& args, TVMRetValue* rv) {
77-
runtime::detail::unpack_call<Expr, 1>(MakeYoloRegion, args, rv);
78-
});
79-
80-
81-
RELAY_REGISTER_OP("vision.yolo_region")
82-
.describe(R"doc("Yolo region operation used for detection."
83-
)doc" TVM_ADD_FILELINE)
84-
.add_argument("data", "Tensor", "The input tensor.")
85-
.set_num_inputs(1)
86-
.set_support_level(5)
87-
.add_type_rel("Identity", IdentityRel);
88-
89-
90-
Expr MakeYolov3Yolo(Expr data) {
91-
static const Op& op = Op::Get("vision.yolov3_yolo");
92-
return CallNode::make(op, {data}, Attrs(), {});
93-
}
94-
95-
96-
TVM_REGISTER_API("relay.op.vision._make.yolov3_yolo")
97-
.set_body([](const TVMArgs& args, TVMRetValue* rv) {
98-
runtime::detail::unpack_call<Expr, 1>(MakeYolov3Yolo, args, rv);
99-
});
100-
101-
102-
RELAY_REGISTER_OP("vision.yolov3_yolo")
103-
.describe(R"doc("Yolov3 operation used for detection."
104-
)doc" TVM_ADD_FILELINE)
105-
.add_argument("data", "Tensor", "The input tensor.")
106-
.set_num_inputs(1)
107-
.set_support_level(5)
108-
.add_type_rel("Identity", IdentityRel);
109-
11068
} // namespace relay
11169
} // namespace tvm

tests/python/relay/test_op_level5.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,19 @@ def test_multibox_prior():
4646

4747
def test_yolo_reorg():
4848
n, c, h, w = tvm.var("n"), tvm.var("c"), tvm.var("h"), tvm.var("w")
49-
x = relay.var("x", relay.TensorType((n, c, h, w), "float32"))
50-
z = relay.vision.yolo_reorg(x)
49+
x = relay.var("x", relay.TensorType((n, c, 20, 20), "float32"))
50+
z = relay.vision.yolo_reorg(x, stride=10)
5151
zz = relay.ir_pass.infer_type(z)
52-
assert zz.checked_type == relay.ty.TensorType((n, c, h, w), "float32")
52+
assert "stride=10" in z.astext()
53+
assert zz.checked_type == relay.ty.TensorType((n, c*10*10, 2, 2), "float32")
5354

5455
x = relay.var("x", relay.TensorType((n, c, h, w), "float32"))
5556
z = relay.vision.yolo_reorg(x, stride=2)
5657
assert "stride=2" in z.astext()
5758
zz = relay.ir_pass.infer_type(z)
5859
assert zz.checked_type == relay.ty.TensorType((n, c*2*2, h/2, w/2), "float32")
5960

60-
61-
def test_yolo_region():
62-
n, c, h, w = tvm.var("n"), tvm.var("c"), tvm.var("h"), tvm.var("w")
63-
x = relay.var("x", relay.TensorType((n, c, h, w), "float32"))
64-
z = relay.vision.yolo_region(x)
65-
zz = relay.ir_pass.infer_type(z)
66-
assert zz.checked_type == relay.ty.TensorType((n, c, h, w), "float32")
67-
68-
69-
def test_yolov3_yolo():
70-
n, c, h, w = tvm.var("n"), tvm.var("c"), tvm.var("h"), tvm.var("w")
71-
x = relay.var("x", relay.TensorType((n, c, h, w), "float32"))
72-
z = relay.vision.yolov3_yolo(x)
73-
zz = relay.ir_pass.infer_type(z)
74-
assert zz.checked_type == relay.ty.TensorType((n, c, h, w), "float32")
75-
76-
7761
if __name__ == "__main__":
7862
test_resize_infer_type()
7963
test_multibox_prior()
8064
test_yolo_reorg()
81-
test_yolo_region()
82-
test_yolov3_yolo()

0 commit comments

Comments
 (0)