Skip to content
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

Add yolov8 ncnn example #5506

Merged
merged 33 commits into from
Aug 15, 2024
Merged

Add yolov8 ncnn example #5506

merged 33 commits into from
Aug 15, 2024

Conversation

whyb
Copy link
Contributor

@whyb whyb commented Jun 12, 2024

Add yolov8 ncnn example

ReadMe
Convert yolov8 model to ncnn model workflow:

step 1:

If you don't want to train the model yourself. You should go to the ultralytics website download the pretrained model file.
original pretrained model from https://docs.ultralytics.com/models/yolov8/#supported-tasks-and-modes

step 2:

run this command.

conda create --name yolov8 python=3.11
conda activate yolov8
pip install ultralytics onnx numpy protobuf

step 3:

save source code file(export_model_to_ncnn.py):

from ultralytics import YOLO
detection_models = [
    ["./Detection-pt/yolov8n.pt", "./Detection-pt/"],
    ["./Detection-pt/yolov8s.pt", "./Detection-pt/"],
    ["./Detection-pt/yolov8m.pt", "./Detection-pt/"],
    ["./Detection-pt/yolov8l.pt", "./Detection-pt/"],
    ["./Detection-pt/yolov8x.pt", "./Detection-pt/"]
]
for model_dict in detection_models:
    model = YOLO(model_dict[0])  # load an official pretrained weight model
    model.export(format="ncnn", dynamic=True, save_dir=model_dict[1], simplify=True)

step 4:

run command:

python export_model_to_ncnn.py

Test Image:

input image(640x640):
640x640

output image(640x640):
output

whyb and others added 28 commits May 16, 2023 10:16
This was referenced Jun 12, 2024
@tencent-adm
Copy link
Member

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ nihui
❌ whyb
You have signed the CLA already but the status is still pending? Let us recheck it.

@nihui nihui merged commit e550419 into Tencent:master Aug 15, 2024
21 of 22 checks passed
@nihui
Copy link
Member

nihui commented Aug 15, 2024

Thanks for your contribution !

@SIXGODLI
Copy link

通过转换之后,param也只有一个输出,无法使用ncnn自带的yolov8进行推理

@whyb
Copy link
Contributor Author

whyb commented Aug 22, 2024

通过转换之后,param也只有一个输出,无法使用ncnn自带的yolov8进行推理

圖片

yolov8 是一个输入1个,输出1个,您遇到的转换问题是因为没安装好环境,或者您是通过的ultralytics源码安装的,且并未使用requirement.txt,或者是python版本过低。

能否提供一些更加具体的问题描述呢?

如果ultralytics官方转换ncnn的方式实在走不通,不妨试试换一个方向:导出torchscript 格式的模型,然后再使用pnnx转换到ncnn模型。

@git-zhan
Copy link

git-zhan commented Aug 22, 2024

按照examples/yolov8.cpp 教程转换成ncnn后用C++推理报错
image

@whyb
Copy link
Contributor Author

whyb commented Aug 22, 2024

按照examples/yolov8.cpp 教程转换成ncnn后用C++推理报错 image

您截图上的报错是因为没有读取到对应的模型文件:yolov8n.paramyolov8n.bin ,可能的原因很多,有可能因为权限,有可能因为路径包含亚洲字符,也可能模型文件不存在。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants