Tencent / ncnn

ncnn is a high-performance neural network inference framework optimized for the mobile platform
Other
20.11k stars 4.14k forks source link

how to convert yolov5-v6.0 to ncnn? #3458

Open nqthai309 opened 2 years ago

nqthai309 commented 2 years ago

i test with ncnn model yolov5 v60 pre-training and it works fine, but when i manually convert pre-training model yolov5m6.pt -> onnx -> ncnn get error like this. Can someone help me.

=> convert onnx -> ncnn image

=> inference ncnn model image

Whu-wxy commented 2 years ago

My command:

python export.py --include onnx --weight path/to/x.pt --img 640 --train --simplify

Have you simplified it?

nqthai309 commented 2 years ago

I do it in this order, help me !!

yolov5m6.pt ---> onnx simplify image

onnx ----> ncnn image

run ncnn model image

Whu-wxy commented 2 years ago

Have you tried yolov5m/s/n or online conversion ?

nqthai309 commented 2 years ago

Have you tried yolov5m/s/n or online conversion ?

I try convert online image

download model then optimize file param and bin image

build and run yolov5 ncnn image

Segmentation fault :(

yu937861 commented 2 years ago

I encountered the same problem and tried many times without solving it。

yu937861 commented 2 years ago

i test with ncnn model yolov5 v60 pre-training and it works fine, but when i manually convert pre-training model yolov5m6.pt -> onnx -> ncnn get error like this. Can someone help me.

=> convert onnx -> ncnn image

=> inference ncnn model image

If you solve it, please tell me your solution.

wangchunin commented 2 years ago

python export.py --weights ./yolov5m.pt --include torchscript onnx --train add "--train"

rgkannan676 commented 2 years ago

Hi @nihui , Can you please advise on this issue. Thanks.

rgkannan676 commented 2 years ago

"python export.py --include onnx --weight path/to/x.pt --img 640 --train --simplify" resolved my error during ncnn conversion.

nqthai309 commented 2 years ago

i try convert pretrained model yolov5m6.pt -> onnx with "python3 export.py --include onnx --weights yolov5m6.pt --train --simplify" then convert onnx model -> ncnn model, but when i load them i get this error image

"python export.py --include onnx --weight path/to/x.pt --img 640 --train --simplify" resolved my error during ncnn conversion.

rgkannan676 commented 2 years ago

You need to change the extract layers in the c++ file. Layers of the current model is mentioned in the error message under “Try”.

rgkannan676 commented 2 years ago

The example script is for yolov5s6 model. I tried with yolov5m6 model and didn’t get good results as you can see that there are 4 output layers. Hi @nihui can you please advise what changes are required for yolov5m6 model? Thanks

nihui commented 1 month ago

针对onnx模型转换的各种问题,推荐使用最新的pnnx工具转换到ncnn In view of various problems in onnx model conversion, it is recommended to use the latest pnnx tool to convert your model to ncnn

pip install pnnx
pnnx model.onnx inputshape=[1,3,224,224]

详细参考文档 Detailed reference documentation https://github.com/pnnx/pnnx https://github.com/Tencent/ncnn/wiki/use-ncnn-with-pytorch-or-onnx#how-to-use-pnnx