-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4300bbc
commit 89d965d
Showing
6 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
from __future__ import absolute_import as _abs | ||
|
||
from .multibox import * | ||
from .yolo import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
"""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. | ||
Parameters | ||
---------- | ||
data : relay.Expr | ||
The input data tensor. | ||
stride : int | ||
The stride value for reorganisation. | ||
Returns | ||
------- | ||
ret : relay.Expr | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/*! | ||
* Copyright (c) 2018 by Contributors | ||
* \file yolo.cc | ||
* \brief Yolo related operators | ||
*/ | ||
#include <tvm/relay/op.h> | ||
#include <tvm/relay/attrs/vision.h> | ||
#include <vector> | ||
#include "../op_common.h" | ||
#include "../type_relations.h" | ||
|
||
namespace tvm { | ||
namespace relay { | ||
|
||
TVM_REGISTER_NODE_TYPE(YoloReorgAttrs); | ||
|
||
/*! | ||
* \brief YoloReorgRel Output type and shape relation evaluation function. | ||
* \param num_inputs Number of input types in the args. | ||
* \param attrs The additional attributes of the operator. | ||
* \param reporter The reporter to report solution to. | ||
* \return false if This relation cannot be resolved. true if this relation has been resolved. | ||
*/ | ||
bool YoloReorgRel(const Array<Type>& types, | ||
int num_inputs, | ||
const Attrs& attrs, | ||
const TypeReporter& reporter) { | ||
CHECK_EQ(types.size(), 2); | ||
const auto* data = types[0].as<TensorTypeNode>(); | ||
if (data == nullptr) return false; | ||
|
||
const YoloReorgAttrs* param = attrs.as<YoloReorgAttrs>(); | ||
CHECK(param != nullptr); | ||
|
||
CHECK(data->shape.size() == 4) << "Yolo reorg supports only 4 dimension."; | ||
std::vector<IndexExpr>&& oshape = AsVector(data->shape); | ||
oshape[1] = oshape[1] * param->stride * param->stride; | ||
oshape[2] = oshape[2] / param->stride; | ||
oshape[3] = oshape[3] / param->stride; | ||
reporter->Assign(types[1], TensorTypeNode::make(oshape, data->dtype)); | ||
return true; | ||
} | ||
|
||
Expr MakeYoloReorg(Expr data, | ||
IndexExpr stride) { | ||
auto attrs = make_node<YoloReorgAttrs>(); | ||
attrs->stride = stride; | ||
static const Op& op = Op::Get("vision.yolo_reorg"); | ||
return CallNode::make(op, {data}, Attrs(attrs), {}); | ||
} | ||
|
||
|
||
TVM_REGISTER_API("relay.op.vision._make.yolo_reorg") | ||
.set_body([](const TVMArgs& args, TVMRetValue* rv) { | ||
runtime::detail::unpack_call<Expr, 2>(MakeYoloReorg, args, rv); | ||
}); | ||
|
||
|
||
RELAY_REGISTER_OP("vision.yolo_reorg") | ||
.describe(R"doc("Yolo reorg operation. This layer reorganize the output. | ||
Its function is mostly shape transform.")doc" TVM_ADD_FILELINE) | ||
.add_argument("data", "Tensor", "The input tensor.") | ||
.set_num_inputs(1) | ||
.set_support_level(5) | ||
.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters