forked from ultralytics/ultralytics
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change training script #6
Open
ErnisMeshi
wants to merge
10
commits into
airockchip:main
Choose a base branch
from
ErnisMeshi:change-training-script
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5b7ddd8
rk opt for yolov8 base@rk_c86cd359
27ae4eb
add onnx package to requirements.txt
831b4c2
changing head.py
0110bb5
changing head.py
3d92387
changing exporter.py
b4b2e21
add arguments for input height and input width
a840257
remove unnecessary prints
2c4f89b
change pypi package name
bf9e441
Merge pull request #1 from ErnisMeshi/conversion_changes
ErnisMeshi 22d08a7
shuffle images even when using rectangular training
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yolo官方改成11了,requirements文件在最新的main分支没有。11的pt模型导出onnx->rknn直接使用v8的方法吗?