diff --git a/docs/langref/relay_op.rst b/docs/langref/relay_op.rst index 83d8149da22b4..e58a1f38fb145 100644 --- a/docs/langref/relay_op.rst +++ b/docs/langref/relay_op.rst @@ -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** @@ -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 diff --git a/python/tvm/relay/op/vision/yolo.py b/python/tvm/relay/op/vision/yolo.py index 36d09417872ed..71b7918dca0f7 100644 --- a/python/tvm/relay/op/vision/yolo.py +++ b/python/tvm/relay/op/vision/yolo.py @@ -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 ---------- @@ -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) diff --git a/src/relay/op/vision/yolo.cc b/src/relay/op/vision/yolo.cc index e82e098d019df..9074b68ebf707 100644 --- a/src/relay/op/vision/yolo.cc +++ b/src/relay/op/vision/yolo.cc @@ -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(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(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 diff --git a/tests/python/relay/test_op_level5.py b/tests/python/relay/test_op_level5.py index 102eafa60720b..c86f20be9e609 100644 --- a/tests/python/relay/test_op_level5.py +++ b/tests/python/relay/test_op_level5.py @@ -72,10 +72,11 @@ 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) @@ -83,27 +84,8 @@ def test_yolo_reorg(): 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()