ncnn icon indicating copy to clipboard operation
ncnn copied to clipboard

onnx2ncnn cannot convert the latest version yolov5s-v6

Open arnoldfychen opened this issue 2 years ago • 11 comments

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 avatar Jun 20 '22 12:06 arnoldfychen

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

arnoldfychen avatar Jun 20 '22 12:06 arnoldfychen

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

wzyforgit avatar Jun 21 '22 00:06 wzyforgit

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 ?

arnoldfychen avatar Jun 21 '22 04:06 arnoldfychen

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.

wzyforgit avatar Jun 21 '22 05:06 wzyforgit

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.

arnoldfychen avatar Jun 21 '22 05:06 arnoldfychen

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.

wzyforgit avatar Jun 21 '22 05:06 wzyforgit

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

tom2002965 avatar Jul 11 '22 10:07 tom2002965

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

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

wzyforgit avatar Jul 12 '22 00:07 wzyforgit

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

tom2002965 avatar Jul 12 '22 01:07 tom2002965

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

Digital2Slave avatar Jul 28 '22 08:07 Digital2Slave

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.

paleomoon avatar Sep 05 '22 13:09 paleomoon