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

yolov8.cpp模型预测速度相比以往差了10倍不止 #5666

Open
fanxiangyu399 opened this issue Sep 1, 2024 · 3 comments
Open

yolov8.cpp模型预测速度相比以往差了10倍不止 #5666

fanxiangyu399 opened this issue Sep 1, 2024 · 3 comments

Comments

@fanxiangyu399
Copy link

fanxiangyu399 commented Sep 1, 2024

经过同一个pt模型测试,
使用yolov8自带的ncnn一键导出了模型,用example的yolov8.cpp去推理速度300-500毫秒之间
网络上那些需要修改head和block所导出的模型再去用旧代码推理发现只要15-30毫秒...

还有个问题是推理的时候如果target_size如果由640改为320就会导致检测结果多至4000多...以前旧版的改了就没问题反而速度会变快

Tasks

No tasks being tracked yet.

Tasks

No tasks being tracked yet.
@whyb
Copy link
Contributor

whyb commented Sep 2, 2024

第一个问题留给其他大佬,我只能回答第二个问题,

如果target_size如果由640改为320就会导致检测结果多至4000多... 的原因是使用ultralytics官方的model.export()函数,即便您使用了 dynamic=True 参数来导出ncnn格式的模型,仍然导出来的是固定640x640 shape,我理解这是他们的bug。

如果您确实有其他图像尺寸的识别需求的话,可能尝试下先用ultralytics官方的model.export()导出torchscript,然后再使用nihui实现的pnnx工具(https://github.com/pnnx/pnnx )将其转换成 dynamic input shape 的ncnn模型。
估计只有这种方案才能达到您的需求,祝您好运~

@fanxiangyu399
Copy link
Author

第一个问题留给其他大佬,我只能回答第二个问题,

如果target_size如果由640改为320就会导致检测结果多至4000多...的原因是使用ultralytics官方的model.export()函数,即便您使用了 dynamic=True 参数来导出ncnn格式的模型,仍然导出来的是固定640x640 shape,我理解这是他们的bug。

如果您确实有其他图像尺寸的识别需求的话,可能尝试下先用ultralytics官方的model.export()导出torchscript,然后再使用nihui实现的pnnx工具(https://github.com/pnnx/pnnx )将其转换成 dynamic input shape 的ncnn模型。 估计只有这种方案才能达到您的需求,祝您好运~

okok,感谢大佬,测试过了ultralytics官方的model.export()加个参数设置imgsz为320那320尺寸的就能用了

@wzyforgit
Copy link
Contributor

第一个问题是因为官方版的把模型后处理给塞进模型里面了,他们图方便就把所有的框都解码出来了。原来那些速度快的版本在解码每个框之前会读取和计算这个框的得分,分数太低就不会去进一步解码。然后因为解码操作里面有矩阵乘法、softmax之类很慢的操作,所以用官方版的反而速度会很慢,虽然开发起来很方便=。=
解决方法就是学隔壁yolov5的example,去找到解码每个框之前的节点,在那个位置将数据给extract出来(ncnn也不会继续计算后续的节点),随后自己写先判断得分后进行解码的后处理,这样速度应该会快很多

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

No branches or pull requests

3 participants