YuvalNirkin / hyperseg

HyperSeg - Official PyTorch Implementation
https://nirkin.com/hyperseg
Creative Commons Zero v1.0 Universal
210 stars 39 forks source link

How to convert the pth file to onnx? #18

Closed ghost closed 2 years ago

ghost commented 2 years ago

Did someone try to convert the pth file to onnx and could help me? I tried, but I met this error: RuntimeError: Unsupported: ONNX export of convolution for kernel of unknown shape.

Further information File "C:\ProgramData\Anaconda3\envs\project\lib\site-packages\torch\onnx\utils.py", line 729, in _export dynamic_axes=dynamic_axes) File "C:\ProgramData\Anaconda3\envs\project\lib\site-packages\torch\onnx\utils.py", line 501, in _model_to_graph module=module) File "C:\ProgramData\Anaconda3\envs\project\lib\site-packages\torch\onnx\utils.py", line 216, in _optimize_graph graph = torch._C.jit_pass_onnx(graph, operator_export_type) File "C:\ProgramData\Anaconda3\envs\project\lib\site-packages\torch\onnx_init.py", line 373, in _run_symbolic_function return utils._run_symbolic_function(*args, kwargs) File "C:\ProgramData\Anaconda3\envs\project\lib\site-packages\torch\onnx\utils.py", line 1032, in _run_symbolic_function return symbolic_fn(g, *inputs, *attrs) File "C:\ProgramData\Anaconda3\envs\project\lib\site-packages\torch\onnx\symbolic_helper.py", line 172, in wrapper return fn(g, args, kwargs) File "C:\ProgramData\Anaconda3\envs\project\lib\site-packages\torch\onnx\symbolic_opset9.py", line 1281, in _convolution raise RuntimeError("Unsupported: ONNX export of convolution for kernel "

Notes Any additional information, code snippets: from torch.autograd import Variable dummy_input = Variable(torch.randn(7, 3, 512, 1024)) state_dict = torch.load('./model_best.pth') model.load_state_dict(state_dict['state_dict']) torch.onnx.export(model, dummy_input, "arch.onnx",opset_version=11)