signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0(Cause: null pointer dereference)

在Android平台上,使用MNN编译的模型推理SO遇到空指针错误。问题源于模型转换,当PyTorch模型转换为ONNX,opset_version=11时会触发错误,而opset_version=10则正常。解决方案是将模型中仅在opset_version=11时可转换的新算子替换为简单算子并重新训练。
摘要由CSDN通过智能技术生成

问题描述:
基于mnn编译的面向安卓平台的模型推理so动态在android studio调用其推理函数时报空指针错误(完整错误输出在最后),且错误行在于mnn推理输出的指针数组元素的判断语句(如下代码),但之前使用其他模型时加入类似语句并未报错,所以猜测问题出在了模型上面

int* output_tensor_array = output_tensor->host<int>();
output_tensor_array[col + 1024 * row] == 2 //此处为addr2line显示的报错点

解决:
经过大量试验,发现在转换pytorch模型至onnx模型时,opset_version=10的模型在后续so调用函数均正常,opset_version=11的均错误,但是目前使用的模型实现中有新的pytorch算子只有在opset_version=11的时候才能转换为onnx格式,最终把该新算子改成简单的算子替代重新训练即可

torch.onnx.export(net,                     # model being run
                x,                         # model input (or a tuple for multiple inputs)
                output_path,               # where to save the model (can be a file or file-like object)
                export_params=True,        # store the trained parameter weights inside the model file
                opset_version=10,          # the ONNX version to export the model to
                do_constant_folding=True,  # whether to execute constant folding for optimization
                input_names = ['input'],   # the model's input names
                output_names = ['output'], # the model's output names
                )

完整错误输出:

2021-07-11 16:07:46.463 29653-29653/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2021-07-11 16:07:46.463 29653-29653/? A/DEBUG: Build fingerprint: 'HUAWEI/MRX-W09/HWMRX:10/HUAWEIMRX-W09/11.0.0.180C00:user/release-keys'
2021-07-11 16:07:46.463 29653-29653/? A/DEBUG: Revision: '0&#
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值