Tencent / ncnn

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

ch_PP-OCRv4_rec_infer 轉換問題 #5395

Open timlliu opened 7 months ago

timlliu commented 7 months ago

模型

ch_PP-OCRv4_rec_infer

版本 python '3.9.6' onnxsim '0.4.7' paddle2onnx '1.0.5'

再現方法

  1. paddle2onnx --model_dir ch_PP-OCRv4_rec_infer --model_filename inference.pdmodel --params_filename inference.pdiparams --save_file ch_PP-OCRv4_rec_infer\rec_onnx\model.onnx --opset_version 16 --input_shape_dict="{'x':[-1,3,-1,-1]}" --enable_onnx_checker True

  2. python -m onnxsim model.onnx model_new.onnx --overwrite-input-shape 1,3,48,320

  3. ncnn-20240102-windows-vs2022-shared/x64/bin/onnx2ncnn.exe model_new.onnx 得到: Unsupported transpose type ! Unsupported transpose type !

  4. 按照 這裡 把 transpose 修改完,之後再將未定義的p2o.helper.constant.37splitncnn-1 ~ 8 換成 p2o.helper.constant.37_splitncnn_0,到目前模型不會跳出錯誤,但是會直接crash。

  5. 分別看每個層的輸出: onnx: "transpose_44.tmp_0_splitncnn_0" (3, 1, 8, 40, 15) "p2o.Slice.5" (1, 1, 8, 40, 15) ncnn: "transpose_44.tmp_0_splitncnn_0" (3, 8, 40, 15) "p2o.Slice.5" (3, 1, 1, 1)

所以目前推測是 Crop 出了問題: 第328行:Crop p2o.Slice.4 3 1 transpose_44.tmp_0_splitncnn_2 p2o.helper.constant.37_splitncnn_5 p2o.helper.constant.37_splitncnn_4 p2o.Slice.5 -23309=0 -23310=0 第331行:Crop p2o.Slice.6 3 1 transpose_44.tmp_0_splitncnn_1 p2o.helper.constant.50 p2o.helper.constant.37_splitncnn_2 p2o.Slice.7 -23309=0 -23310=0 第333行:Crop p2o.Slice.8 3 1 transpose_44.tmp_0_splitncnn_0 p2o.helper.constant.50 p2o.helper.constant.37_splitncnn_0 p2o.Slice.9 -23309=0 -23310=0

onnx 在 p2o.Slice.8 的 參數: image

ncnn 的參數: image

好像少了一些參數像是:p2o.helper.constant.36、p2o.helper.constant.34

到這邊我就卡住了,請問我要怎解決?

模型

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