davidtvs / PyTorch-ENet

PyTorch implementation of ENet
MIT License
383 stars 129 forks source link

Pytorch-ENet to ONNX failed due to unsupported max_unpool2d #57

Closed AP-Kai closed 2 years ago

AP-Kai commented 2 years ago

Hi, when I trained a cityscapes model and I want to change it to onnx, a error occured. I can't solve this problem by myself.

This is the error:

  File "main.py", line 328, in <module>
    test(model, test_loader, w_class, class_encoding)
  File "main.py", line 259, in test
    torch.onnx.export(model, dummy_input, "model.onnx", verbose=True, opset_version=11)
  File "E:\pytorch-venv\lib\site-packages\torch\onnx\__init__.py", line 320, in export
    custom_opsets, enable_onnx_checker, use_external_data_format)
  File "E:\pytorch-venv\lib\site-packages\torch\onnx\utils.py", line 111, in export
    custom_opsets=custom_opsets, use_external_data_format=use_external_data_format)
  File "E:\pytorch-venv\lib\site-packages\torch\onnx\utils.py", line 729, in _export
    dynamic_axes=dynamic_axes)
  File "E:\pytorch-venv\lib\site-packages\torch\onnx\utils.py", line 501, in _model_to_graph
    module=module)
  File "E:\pytorch-venv\lib\site-packages\torch\onnx\utils.py", line 216, in _optimize_graph
    graph = torch._C._jit_pass_onnx(graph, operator_export_type)
  File "E:\pytorch-venv\lib\site-packages\torch\onnx\__init__.py", line 373, in _run_symbolic_function
    return utils._run_symbolic_function(*args, **kwargs)
  File "E:\pytorch-venv\lib\site-packages\torch\onnx\utils.py", line 1028, in _run_symbolic_function
    symbolic_fn = _find_symbolic_in_registry(domain, op_name, opset_version, operator_export_type)
  File "E:\pytorch-venv\lib\site-packages\torch\onnx\utils.py", line 982, in _find_symbolic_in_registry
    return sym_registry.get_registered_op(op_name, domain, opset_version)
  File "E:\pytorch-venv\lib\site-packages\torch\onnx\symbolic_registry.py", line 125, in get_registered_op
    raise RuntimeError(msg)
**RuntimeError: Exporting the operator max_unpool2d to ONNX opset version 11 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.**

This is my environment:

OS: Windows 10
torch             1.10.0+cu102
torchaudio        0.10.0+cu102
torchvision       0.11.1+cu102

Could you give me some advice to solve this problem?

davidtvs commented 2 years ago

Not much I can do about it. It's an issue with PyTorch and ONNX, see here: https://github.com/pytorch/pytorch/issues/25088

A workaround is to replace the max_unpool layers with transposed convolutions layers; at the cost of more parameters.

mryoungci commented 1 year ago

RuntimeError: Exporting the operator max_unpool2d to ONNX opset version 11 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub. 解决方案:将max_unpool2d 操作改为 nn.ConvTranspose2d操作 ———————————————— 原文链接:https://blog.csdn.net/qq_41375318/article/details/127287645