1. import torch
    2. from torch import onnx
    3. dummy_input = torch.randn(10,3,256,256).cuda()
    4. path = './net.pt'
    5. model = torch.load(path)
    6. input_names = ['input']
    7. output_names = ['output']
    8. torch.onnx.export(model, dummy_input,'net.onnx' ,verbose=True, input_names=input_names, output_names=output_names,opset_version=11)

    opset_version=11
    版本要低 ,最好为9,这样onnxruntime 版本低 接口兼容。

    onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Got invalid dimensions for input: input for the following indices