Tencent / ncnn

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

onnx2ncnn cannot convert the latest version yolov5s-v6 #3936

Open arnoldfychen opened 2 years ago

arnoldfychen commented 2 years ago

error log | 日志或报错信息 | ログ

Shape not supported yet! Gather not supported yet!

axis=0

Shape not supported yet! Gather not supported yet!

axis=0

Shape not supported yet! Gather not supported yet!

axis=0

Unknown data type 0 Unsupported slice axes ! Unsupported slice axes ! Unsupported slice axes ! Unknown data type 0 Shape not supported yet! Gather not supported yet!

axis=0

Shape not supported yet! Gather not supported yet!

axis=0

Shape not supported yet! Gather not supported yet!

axis=0

Unknown data type 0 Unsupported slice axes ! Unsupported slice axes ! Unsupported slice axes ! Unknown data type 0 Shape not supported yet! Gather not supported yet!

axis=0

Shape not supported yet! Gather not supported yet!

axis=0

Shape not supported yet! Gather not supported yet!

axis=0

Unknown data type 0 Unsupported slice axes ! Unsupported slice axes ! Unsupported slice axes ! Unknown data type 0

context | 编译/运行环境 | バックグラウンド

how to reproduce | 复现步骤 | 再現方法

  1. train out a model with the latest yolov5s-v6 code under https://github.com/ultralytics/yolov5
  2. export an onnx file with the export.py by 'python export.py --simplify --weights '
  3. under ncnn/tools/onnx/, execute './onnx2ncnn <.param file> <.bin>', you will see many error or caution messages are printed out, although the param file and the bin file are generated, the content in the param file is not right, use netron.app to parse out the network graph and find the result is much different than that parsed out by https://github.com/nihui/ncnn-assets/blob/master/models/yolov5s_6.0.param, and certainly the example code yolov5.cpp cannot run well with the wrong param and bin files.

    more | 其他 | その他

    The above error or caution messages also can be seen if you parse the onnx to nccn target on https://convertmodel.com

arnoldfychen commented 2 years ago

P.S., I can provide you the model onnx for reproducing this issue to help the progress of resolving it

wzyforgit commented 2 years ago

if your train framework is Pytorch, please use PNNX to convert your model to ncnn

arnoldfychen commented 2 years ago

if your train framework is Pytorch, please use PNNX to convert your model to ncnn

Thank you, but it looks like pnnx is not formally included in the tools CMake project yet ?

wzyforgit commented 2 years ago

Thank you, but it looks like pnnx is not formally included in the tools CMake project yet ?

You are wrong, PNNX is the most important tool to convert model from Pytorch.

arnoldfychen commented 2 years ago

I mean the pnnx tool under ncnn/tools, after having built ncnn, pnnx is not found under tools, and checked the CMakeLists.txt under tools, pnnx directory is not included.

wzyforgit commented 2 years ago

I mean the pnnx tool under ncnn/tools, after having built ncnn, pnnx is not found under tools, and checked the CMakeLists.txt under tools, pnnx directory is not included.

Yes you are right, but it's really the most important tool to convert model from Pytorch to ncnn.

tom2002965 commented 2 years ago

Why CMakeLists.txt does not include pnnx? is pnnx still not a stable?

wzyforgit commented 2 years ago

Why CMakeLists.txt does not include pnnx? is pnnx still not a stable?

非常的stable啊,你們哪裏感覺它不stable的? 不加進去估計是因爲編譯需要依賴libtorch,那個東西有點大

tom2002965 commented 2 years ago

NCNN 的 CMakeLists 很強大阿,支援各種compile flag。 倘若source code 已經放在ncnn/tools 底下,但CMakeLists 沒放進去,想必有其原因吧? 看來真如您所說,需要 libtorch,這並不是所有人都需要且超過此project的範疇了!

Digital2Slave commented 2 years ago

For yolov5-v6.1

# convert .pt to .onnx
python3 export.py --weights path/to/your/*.pt --include onnx --train

# convert .onnx to *-sim.onnx
pip3 install onnx-simplifier
python3 -m onnxsim  path/to/your/*.onnx path/to/your/*-sim.onnx

# out-of-the-box web model conversion
https://convertmodel.com/#outputFormat=ncnn

image

paleomoon commented 2 years ago

One can use onnx2ncnn or pnnx to convert yolov5 pytorch model without Detect() layer to ncnn, that is export with --train option.

If use pnnx, you have no need to compile it: https://github.com/pnnx/pnnx/releases

But I think it's better to export with Detect() layer, so you don't have to deal with anchors (anchors may change with models), hope this can be supported in the future.

nihui commented 3 months 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

zengjie617789 commented 2 days ago

使用了pnnx转换 @nihui 但是nccn中的shape与pnnx对于不上;输入shape为[1,368,64]