ncnn icon indicating copy to clipboard operation
ncnn copied to clipboard

Add yolov8 ncnn example

Open whyb opened this issue 1 year ago • 1 comments

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 avatar Jun 12 '24 07:06 whyb

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.

:white_check_mark: nihui
:x: whyb
You have signed the CLA already but the status is still pending? Let us recheck it.

tencent-adm avatar Jun 20 '24 05:06 tencent-adm

Thanks for your contribution !

nihui avatar Aug 15 '24 08:08 nihui

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

SIXGODLI avatar Aug 21 '24 13:08 SIXGODLI

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

圖片

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

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

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

whyb avatar Aug 22 '24 07:08 whyb

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

git-zhan avatar Aug 22 '24 10:08 git-zhan

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

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

whyb avatar Aug 22 '24 14:08 whyb