Skip to content

Commit

Permalink
[Feature] Support YOLOv5 deployment at RV1126 device (open-mmlab#262)
Browse files Browse the repository at this point in the history
* add yolov5 head rewrite and rknn config

* type hint

* remove useless

* refactor config
  • Loading branch information
AllentDan authored and triple-Mu committed Dec 6, 2022
1 parent d7e6efd commit 7c8943a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions configs/deploy/detection_rknn-fp16_static-320x320.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_base_ = ['./base_static.py']
onnx_config = dict(
input_shape=[320, 320], output_names=['feat0', 'feat1', 'feat2'])
codebase_config = dict(model_type='rknn')
backend_config = dict(
type='rknn',
common_config=dict(target_platform='rv1126', optimization_level=1),
quantization_config=dict(do_quantization=False, dataset=None),
input_size_list=[[3, 320, 320]])
9 changes: 9 additions & 0 deletions configs/deploy/detection_rknn-int8_static-320x320.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
_base_ = ['./base_static.py']
onnx_config = dict(
input_shape=[320, 320], output_names=['feat0', 'feat1', 'feat2'])
codebase_config = dict(model_type='rknn')
backend_config = dict(
type='rknn',
common_config=dict(target_platform='rv1126', optimization_level=1),
quantization_config=dict(do_quantization=True, dataset=None),
input_size_list=[[3, 320, 320]])
31 changes: 31 additions & 0 deletions mmyolo/deploy/models/dense_heads/yolov5_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,34 @@ def yolov5_head__predict_by_feat(ctx,

return nms_func(bboxes, scores, max_output_boxes_per_class, iou_threshold,
score_threshold, pre_top_k, keep_top_k)


@FUNCTION_REWRITER.register_rewriter(
func_name='mmyolo.models.dense_heads.yolov5_head.'
'YOLOv5Head.predict',
backend='rknn')
def yolov5_head__predict__rknn(ctx, self, x: Tuple[Tensor], *args,
**kwargs) -> Tuple[Tensor, Tensor, Tensor]:
"""Perform forward propagation of the detection head and predict detection
results on the features of the upstream network.
Args:
x (tuple[Tensor]): Multi-level features from the
upstream network, each is a 4D-tensor.
"""
outs = self(x)
return outs


@FUNCTION_REWRITER.register_rewriter(
func_name='mmyolo.models.dense_heads.yolov5_head.'
'YOLOv5HeadModule.forward',
backend='rknn')
def yolov5_head_module__forward__rknn(
ctx, self, x: Tensor, *args,
**kwargs) -> Tuple[Tensor, Tensor, Tensor]:
"""Forward feature of a single scale level."""
out = []
for i, feat in enumerate(x):
out.append(self.convs_pred[i](feat))
return out

0 comments on commit 7c8943a

Please sign in to comment.