Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Exporting the operator linspace to ONNX opset version 11 is not supported #14

Open
frotms opened this issue Mar 17, 2022 · 2 comments

Comments

@frotms
Copy link

frotms commented Mar 17, 2022

I run

python deploy/onnx_exporter_solov2.py configs/solov2/solov2_light_448_r18_fpn_8gpu_3x.py weights/SOLOv2_LIGHT_448_R18_3x.onnx --checkpoint ./checkpoints/SOLOv2_LIGHT_448_R18_3x.pth --shape 448 672

and got,

Traceback (most recent call last): File "deploy/onnx_exporter_solov2.py", line 225, in <module> convert2onnx(args, dummy_input) File "deploy/onnx_exporter_solov2.py", line 100, in convert2onnx torch.onnx.export(model, dummy_input, args.out, input_names=input_names, output_names=output_names, verbose=True, opset_version=11) File "/opt/conda/lib/python3.7/site-packages/torch/onnx/__init__.py", line 276, in export custom_opsets, enable_onnx_checker, use_external_data_format) File "/opt/conda/lib/python3.7/site-packages/torch/onnx/utils.py", line 94, in export use_external_data_format=use_external_data_format) File "/opt/conda/lib/python3.7/site-packages/torch/onnx/utils.py", line 701, in _export dynamic_axes=dynamic_axes) File "/opt/conda/lib/python3.7/site-packages/torch/onnx/utils.py", line 468, in _model_to_graph module=module) File "/opt/conda/lib/python3.7/site-packages/torch/onnx/utils.py", line 206, in _optimize_graph graph = torch._C._jit_pass_onnx(graph, operator_export_type) File "/opt/conda/lib/python3.7/site-packages/torch/onnx/__init__.py", line 309, in _run_symbolic_function return utils._run_symbolic_function(*args, **kwargs) File "/opt/conda/lib/python3.7/site-packages/torch/onnx/utils.py", line 993, in _run_symbolic_function symbolic_fn = _find_symbolic_in_registry(domain, op_name, opset_version, operator_export_type) File "/opt/conda/lib/python3.7/site-packages/torch/onnx/utils.py", line 950, in _find_symbolic_in_registry return sym_registry.get_registered_op(op_name, domain, opset_version) File "/opt/conda/lib/python3.7/site-packages/torch/onnx/symbolic_registry.py", line 116, in get_registered_op raise RuntimeError(msg) RuntimeError: Exporting the operator linspace to ONNX opset version 11 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.

@angiewlz
Copy link

readme里写了:
pytorch 1.4 不支持onnx导出 torch.linspace()
修改 torch/onnx/symbolic_opset11.py, 增加如下代码段:
def linspace(g, start, end, steps, dtype, *options): parsed_dtype = sym_help._get_const(dtype, 'i', 'dtype') steps_ = sym_help._get_const(steps, 'i', 'steps') if steps_ == 1: return g.op("Cast", start, to_i=sym_help.scalar_type_to_onnx[parsed_dtype]) diff = g.op("Cast", g.op("Sub", end, start), to_i=sym_help.cast_pytorch_to_onnx['Double']) delta = g.op("Div", diff, g.op("Constant", value_t=torch.tensor(steps_ - 1, dtype=torch.double))) end = g.op("Add", g.op("Cast", end, to_i=sym_help.cast_pytorch_to_onnx['Double']), delta) start = g.op("Cast", start, to_i=sym_help.cast_pytorch_to_onnx['Double']) return g.op("Cast", g.op("Range", start, end, delta), to_i=sym_help.scalar_type_to_onnx[parsed_dtype])

@lix19937
Copy link

lix19937 commented May 4, 2024

use torch.arrange replace torch.linspace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants