SOLOv2.tensorRT icon indicating copy to clipboard operation
SOLOv2.tensorRT copied to clipboard

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

Open frotms opened this issue 2 years ago • 2 comments

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.

frotms avatar Mar 17 '22 07:03 frotms

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])

angiewlz avatar Mar 17 '22 08:03 angiewlz

use torch.arrange replace torch.linspace

lix19937 avatar May 04 '24 06:05 lix19937