ncnn pnnx使用出现std::out_of_range

iovurdzv  于 4个月前  发布在  其他
关注(0)|答案(1)|浏览(69)

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

terminate called after throwing an instance of 'std::out_of_range'
what(): map::at
Traceback (most recent call last):
File "Test_img.py", line 228, in
main()
File "Test_img.py", line 200, in main
convert_to_libtorch(model, pt_model_name, imgL, imgR)
File "Test_img.py", line 155, in convert_to_libtorch
pnnx.export(model, pnnx_path, (x1, x2), moduleop='torchscript', optlevel=1)
File "/home/ubuntu/.local/lib/python3.8/site-packages/pnnx/utils/export.py", line 33, in export
return convert(ptpath, inputs, inputs2, input_shapes, input_types, input_shapes2, input_types2, device, customop, moduleop, optlevel, pnnxparam, pnnxbin, pnnxpy, pnnxonnx, ncnnparam, ncnnbin, ncnnpy, fp16)
File "/home/ubuntu/.local/lib/python3.8/site-packages/pnnx/utils/convert.py", line 168, in convert
spec.loader.exec_module(foo)
File "", line 844, in exec_module
File "", line 981, in get_code
File "", line 911, in source_to_code
File "", line 219, in call_with_frames_removed
File "/home/ubuntu/git/RTS/./ncnn/RTSNet_libtorch_pnnx_pnnx.py", line 607
v_1948 = v_1877.contiguous(memory_format=torch.contiguous

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

ubuntu 20.04
ncnn-20240102

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

1.转换代码

x1 = torch.rand(1, 3, 480, 640)
    x2 = torch.rand(1, 3, 480, 640)
    pnnx.export(model, pnnx_path, (x1, x2), moduleop='torchscript', optlevel=1)

2.若optlevel=2,会成功,但是模型输出结果不正确

more | 其他 | その他

1.做过交叉验证,模型转为onnx和pt,已经测试模型均没有问题,对应推理结果正确
2.使用pt,再使用ncnn-20240102版本pnnx转换为ncnn,会有相同的现象,即optlevel=2结果不正确,=1时出现std::out_of_range问题

mtb9vblg

mtb9vblg1#

针对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

相关问题