forked from ultralytics/ultralytics
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Randall Zhuo <[email protected]>
- Loading branch information
Randall Zhuo
committed
Dec 19, 2023
1 parent
c9be1f3
commit 5b7ddd8
Showing
12 changed files
with
761 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# RKNN optimization for exporting model | ||
|
||
## Source | ||
Base on https://github.com/ultralytics/ultralytics with commit id as c9be1f3cce89778f79fb462797b8ca0300e3813d | ||
|
||
|
||
|
||
|
||
## What different | ||
With inference result values unchanged, the following optimizations were applied: | ||
- Change output node, remove post-process from the model. (post-process block in model is unfriendly for quantization) | ||
- Remove dfl structure at the end of the model. (which slowdown the inference speed on NPU device) | ||
- Add a score-sum output branch to speedup post-process. | ||
|
||
All the removed operation will be done on CPU. (the CPU post-process could be found in **RKNN_Model_Zoo**) | ||
|
||
|
||
|
||
|
||
## Export ONNX model | ||
|
||
After meeting the environment requirements specified in "./requirements.txt," execute the following command to export the model (support detect/segment model): | ||
|
||
``` | ||
# Adjust the model file path in "./ultralytics/cfg/default.yaml" (default is yolov8n.pt). If you trained your own model, please provide the corresponding path. | ||
# For example, filled with yolov8n.pt for detection model. | ||
# Filling with yolov8n-seg.pt for segmentation model. | ||
export PYTHONPATH=./ | ||
python ./ultralytics/engine/exporter.py | ||
# Upon completion, the ".onnx" model will be generated. If the original model is "yolov8n.pt," the generated model will be "yolov8n.onnx" | ||
``` | ||
|
||
|
||
|
||
## Convert to RKNN model, Python demo, C demo | ||
|
||
Please refer to https://github.com/airockchip/rknn_model_zoo. |
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,45 @@ | ||
# 导出 RKNPU 适配模型说明 | ||
|
||
## Source | ||
|
||
本仓库基于 https://github.com/ultralytics/ultralytics 仓库的 c9be1f3cce89778f79fb462797b8ca0300e3813d commit 进行修改,验证. | ||
|
||
|
||
|
||
## 模型差异 | ||
|
||
在基于不影响输出结果, 不需要重新训练模型的条件下, 有以下改动: | ||
|
||
- 修改输出结构, 移除后处理结构. (后处理结果对于量化不友好) | ||
|
||
- dfl 结构在 NPU 处理上性能不佳,移至模型外部的后处理阶段,此操作大部分情况下可提升推理性能。 | ||
|
||
|
||
- 模型输出分支新增置信度的总和,用于后处理阶段加速阈值筛选。 | ||
|
||
|
||
以上移除的操作, 均需要在外部使用CPU进行相应的处理. (对应的后处理代码可以在 **RKNN_Model_Zoo** 中找到) | ||
|
||
|
||
|
||
## 导出onnx模型 | ||
|
||
在满足 ./requirements.txt 的环境要求后,执行以下语句导出模型 | ||
|
||
``` | ||
# 调整 ./ultralytics/cfg/default.yaml 中 model 文件路径,默认为 yolov8n.pt,若自己训练模型,请调接至对应的路径。支持检测、分割模型。 | ||
# 如填入 yolov8n.pt 导出检测模型 | ||
# 如填入 yolov8-seg.pt 导出分割模型 | ||
export PYTHONPATH=./ | ||
python ./ultralytics/engine/exporter.py | ||
# 执行完毕后,会生成 ONNX 模型. 假如原始模型为 yolov8n.pt,则生成 yolov8n.onnx 模型。 | ||
``` | ||
|
||
|
||
|
||
## 转RKNN模型、Python demo、C demo | ||
|
||
请参考 https://github.com/airockchip/rknn_model_zoo | ||
|
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
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
Oops, something went wrong.