pnnx使用出现std::out_of_range
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
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问题
针对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