import torch
from torch import onnx
dummy_input = torch.randn(10,3,256,256).cuda()
path = './net.pt'
model = torch.load(path)
input_names = ['input']
output_names = ['output']
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