Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
siju-samuel committed Nov 22, 2018
1 parent 78194b4 commit 5a81ae0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 105 deletions.
8 changes: 2 additions & 6 deletions docs/langref/relay_op.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ This level enables additional math and transform operators.
:nosignatures:

tvm.relay.image.resize
tvm.relay.vision.yolo_regorg
tvm.relay.vision.yolo_region
tvm.relay.vision.yolov3_yolo
tvm.relay.vision.yolo_reorg


**Level 10: Temporary Operators**
Expand Down Expand Up @@ -238,9 +236,7 @@ Level 4 Definitions
Level 5 Definitions
-------------------
.. autofunction:: tvm.relay.image.resize
autofunction:: tvm.relay.vision.yolo_regorg
autofunction:: tvm.relay.vision.yolo_region
autofunction:: tvm.relay.vision.yolov3_yolo
autofunction:: tvm.relay.vision.yolo_reorg


Level 10 Definitions
Expand Down
51 changes: 16 additions & 35 deletions python/tvm/relay/op/vision/yolo.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
"""Yolo operations."""
from . import _make

def yolo_reorg(data, stride=1):
"""Yolo reorg operation. This layer reorganize the output based on the stride value.
Its function is mostly shape transform.
def yolo_reorg(data, stride):
"""Yolo reorg operation used in darknet models.
This layer shuffles the input tensor values based on the stride value.
Along with the shuffling, it does the shape transform.
If '(n, c, h, w)' is the data shape and 's' is stride, output shape is '(n, c*s*s, h/s, w/s)'
Example: data(1, 4, 2, 2) = [[[[ 0 1] [ 2 3]]
[[ 4 5] [ 6 7]]
[[ 8 9] [10 11]]
[[12 13] [14 15]]]]
stride = 2
ret(1, 16, 1, 1) = [[[[ 0]] [[ 2]] [[ 8]] [[10]]
[[ 1]] [[ 3]] [[ 9]] [[11]]
[[ 4]] [[ 6]] [[12]] [[14]]
[[ 5]] [[ 7]] [[13]] [[15]]]]
Note: stride=1 has no significance for reorg operation.
Parameters
----------
Expand All @@ -19,35 +32,3 @@ def yolo_reorg(data, stride=1):
The computed result.
"""
return _make.yolo_reorg(data, stride)


def yolo_region(data):
"""Yolo region operation used for detection.
Parameters
----------
data : relay.Expr
The input data tensor.
Returns
-------
ret : relay.Expr
The computed result.
"""
return _make.yolo_region(data)


def yolov3_yolo(data):
"""Yolo operation used for detection
Parameters
----------
data : relay.Expr
The input data tensor.
Returns
-------
ret : relay.Expr
The computed result.
"""
return _make.yolov3_yolo(data)
42 changes: 0 additions & 42 deletions src/relay/op/vision/yolo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,47 +65,5 @@ Its function is mostly shape transform.")doc" TVM_ADD_FILELINE)
.set_attrs_type_key("relay.attrs.YoloReorgAttrs")
.add_type_rel("YoloReorg", YoloReorgRel);


Expr MakeYoloRegion(Expr data) {
static const Op& op = Op::Get("vision.yolo_region");
return CallNode::make(op, {data}, Attrs(), {});
}


TVM_REGISTER_API("relay.op.vision._make.yolo_region")
.set_body([](const TVMArgs& args, TVMRetValue* rv) {
runtime::detail::unpack_call<Expr, 1>(MakeYoloRegion, args, rv);
});


RELAY_REGISTER_OP("vision.yolo_region")
.describe(R"doc("Yolo region operation used for detection."
)doc" TVM_ADD_FILELINE)
.add_argument("data", "Tensor", "The input tensor.")
.set_num_inputs(1)
.set_support_level(5)
.add_type_rel("Identity", IdentityRel);


Expr MakeYolov3Yolo(Expr data) {
static const Op& op = Op::Get("vision.yolov3_yolo");
return CallNode::make(op, {data}, Attrs(), {});
}


TVM_REGISTER_API("relay.op.vision._make.yolov3_yolo")
.set_body([](const TVMArgs& args, TVMRetValue* rv) {
runtime::detail::unpack_call<Expr, 1>(MakeYolov3Yolo, args, rv);
});


RELAY_REGISTER_OP("vision.yolov3_yolo")
.describe(R"doc("Yolov3 operation used for detection."
)doc" TVM_ADD_FILELINE)
.add_argument("data", "Tensor", "The input tensor.")
.set_num_inputs(1)
.set_support_level(5)
.add_type_rel("Identity", IdentityRel);

} // namespace relay
} // namespace tvm
26 changes: 4 additions & 22 deletions tests/python/relay/test_op_level5.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,20 @@ def test_nms():
(n, num_anchors, 6), "float32")
def test_yolo_reorg():
n, c, h, w = tvm.var("n"), tvm.var("c"), tvm.var("h"), tvm.var("w")
x = relay.var("x", relay.TensorType((n, c, h, w), "float32"))
z = relay.vision.yolo_reorg(x)
x = relay.var("x", relay.TensorType((n, c, 20, 20), "float32"))
z = relay.vision.yolo_reorg(x, stride=10)
zz = relay.ir_pass.infer_type(z)
assert zz.checked_type == relay.ty.TensorType((n, c, h, w), "float32")
assert "stride=10" in z.astext()
assert zz.checked_type == relay.ty.TensorType((n, c*10*10, 2, 2), "float32")

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


def test_yolo_region():
n, c, h, w = tvm.var("n"), tvm.var("c"), tvm.var("h"), tvm.var("w")
x = relay.var("x", relay.TensorType((n, c, h, w), "float32"))
z = relay.vision.yolo_region(x)
zz = relay.ir_pass.infer_type(z)
assert zz.checked_type == relay.ty.TensorType((n, c, h, w), "float32")


def test_yolov3_yolo():
n, c, h, w = tvm.var("n"), tvm.var("c"), tvm.var("h"), tvm.var("w")
x = relay.var("x", relay.TensorType((n, c, h, w), "float32"))
z = relay.vision.yolov3_yolo(x)
zz = relay.ir_pass.infer_type(z)
assert zz.checked_type == relay.ty.TensorType((n, c, h, w), "float32")


if __name__ == "__main__":
test_resize_infer_type()
test_multibox_prior()
test_nms()
test_yolo_reorg()
test_yolo_region()
test_yolov3_yolo()

0 comments on commit 5a81ae0

Please sign in to comment.