pytorch1.4 + onnx问题

onnxruntime:https://github.com/microsoft/onnxruntime/
pytorch1.4 + onnx1.6
onnx.checker.check_model(onnx_model) 会报错
onnx降版本到1.5,运行通过

pip install onnx
pip install onnxruntime
pip install onnx-simplifier

参考链接:

https://www.jianshu.com/p/fa2ea3750554
https://blog.csdn.net/cc13949459188/article/details/96427493

caffe2加载onnx文件报错:

    model = onnx.optimizer.optimize(model)
  File "/home/chl/.conda/envs/pytorch_1.4/lib/python3.6/site-packages/onnx/optimizer.py", line 55, in optimize
    optimized_model_str = C.optimize(model_str, passes)
IndexError: _Map_base::at

在pytorch导出的时候设置参数:keep_initializers_as_inputs=True

torch_out = torch.onnx.export(res_model, x, output_onnx, export_params=True, verbose=False, input_names=input_names, output_names=output_names, opset_version=9, keep_initializers_as_inputs=True)

原因是导出模型时使用了CPU,导入caffe2时默认使用CUDA,导致错误。
参考链接:

https://blog.csdn.net/weixin_38331384/article/details/103897154

移植:

https://blog.csdn.net/u011961856/article/details/102478346

你可能感兴趣的:(pytorch基础,ncnn)