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

Error when running export_rtdetr_ultralytics:Unsupported: ONNX export of operator get_pool_ceil_padding, input size not accessible #559

Open
tms2003 opened this issue Aug 7, 2024 · 2 comments

Comments

@tms2003
Copy link

tms2003 commented Aug 7, 2024

this is my command:

python3 export_rtdetr_ultralytics.py -w rtdetr-l.pt --simplify --batch 4 -s 640

and got this error:

python3 export_rtdetr_ultralytics.py -w rtdetr-l.pt  --simplify --batch 4 -s 640

Starting: rtdetr-l.pt
Opening RT-DETR Ultralytics model

Ultralytics YOLOv8.2.73 🚀 Python-3.10.12 torch-2.1.1+cu121 CPU (Intel Core(TM) i5-4590 3.30GHz)
rt-detr-l summary: 494 layers, 32,148,140 parameters, 0 gradients, 103.8 GFLOPs

Creating labels.txt file

Exporting the model to ONNX
Traceback (most recent call last):
  File "/opt/nvidia/deepstream/ultralytics/export_rtdetr_ultralytics.py", line 124, in <module>
    sys.exit(main(args))
  File "/opt/nvidia/deepstream/ultralytics/export_rtdetr_ultralytics.py", line 92, in main
    torch.onnx.export(model, onnx_input_im, onnx_output_file, verbose=False, opset_version=args.opset,
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 516, in export
    _export(
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 1596, in _export
    graph, params_dict, torch_out = _model_to_graph(
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 1139, in _model_to_graph
    graph = _optimize_graph(
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 677, in _optimize_graph
    graph = _C._jit_pass_onnx(graph, operator_export_type)
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py", line 1940, in _run_symbolic_function
    return symbolic_fn(graph_context, *inputs, **attrs)
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/symbolic_helper.py", line 395, in wrapper
    return fn(g, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/symbolic_helper.py", line 306, in wrapper
    return fn(g, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/symbolic_opset10.py", line 203, in symbolic_fn
    padding_ceil = opset9.get_pool_ceil_padding(
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/symbolic_opset9.py", line 1565, in get_pool_ceil_padding
    return symbolic_helper._unimplemented(
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/symbolic_helper.py", line 612, in _unimplemented
    _onnx_unsupported(f"{op}, {msg}", value)
  File "/usr/local/lib/python3.10/dist-packages/torch/onnx/symbolic_helper.py", line 623, in _onnx_unsupported
    raise errors.SymbolicValueError(
torch.onnx.errors.SymbolicValueError: Unsupported: ONNX export of operator get_pool_ceil_padding, input size not accessible. Please feel free to request support or submit a pull request on PyTorch GitHub: https://github.com/pytorch/pytorch/issues  [Caused by the value 'input.4 defined in (%input.4 : Float(*, *, *, *, strides=[3297312, 103041, 321, 1], requires_grad=0, device=cpu) = onnx::Pad[mode="constant"](%449, %476, %452), scope: torch.nn.modules.container.Sequential::/ultralytics.nn.tasks.DetectionModel::0/ultralytics.nn.modules.block.HGStem::model.0 # /opt/nvidia/deepstream/ultralytics/ultralytics/nn/modules/block.py:114:0
)' (type 'Tensor') in the TorchScript graph. The containing node has kind 'onnx::Pad'.] 
    (node defined in /opt/nvidia/deepstream/ultralytics/ultralytics/nn/modules/block.py(114): forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1508): _slow_forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1527): _call_impl
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1518): _wrapped_call_impl
/opt/nvidia/deepstream/ultralytics/ultralytics/nn/tasks.py(141): _predict_once
/opt/nvidia/deepstream/ultralytics/ultralytics/nn/tasks.py(120): predict
/opt/nvidia/deepstream/ultralytics/ultralytics/nn/tasks.py(102): forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1508): _slow_forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1527): _call_impl
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1518): _wrapped_call_impl
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/container.py(215): forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1508): _slow_forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1527): _call_impl
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1518): _wrapped_call_impl
/usr/local/lib/python3.10/dist-packages/torch/jit/_trace.py(124): wrapper
/usr/local/lib/python3.10/dist-packages/torch/jit/_trace.py(133): forward
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1527): _call_impl
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py(1518): _wrapped_call_impl
/usr/local/lib/python3.10/dist-packages/torch/jit/_trace.py(1285): _get_trace_graph
/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py(915): _trace_and_get_graph_from_model
/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py(1011): _create_jit_graph
/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py(1135): _model_to_graph
/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py(1596): _export
/usr/local/lib/python3.10/dist-packages/torch/onnx/utils.py(516): export
/opt/nvidia/deepstream/ultralytics/export_rtdetr_ultralytics.py(92): main
/opt/nvidia/deepstream/ultralytics/export_rtdetr_ultralytics.py(124): <module>
)

    Inputs:
        #0: 449 defined in (%449 : Float(4, 32, 320, 320, strides=[3276800, 102400, 320, 1], requires_grad=0, device=cpu) = onnx::Relu(%input), scope: torch.nn.modules.container.Sequential::/ultralytics.nn.tasks.DetectionModel::0/ultralytics.nn.modules.block.HGStem::model.0/ultralytics.nn.modules.conv.Conv::stem1/torch.nn.modules.activation.ReLU::act # /usr/local/lib/python3.10/dist-packages/torch/nn/functional.py:1469:0
    )  (type 'Tensor')
        #1: 476 defined in (%476 : Long(8, strides=[1], device=cpu) = onnx::Cast[to=7](%475), scope: torch.nn.modules.container.Sequential::/ultralytics.nn.tasks.DetectionModel::0/ultralytics.nn.modules.block.HGStem::model.0 # /opt/nvidia/deepstream/ultralytics/ultralytics/nn/modules/block.py:114:0
    )  (type 'Tensor')
        #2: 452 defined in (%452 : NoneType = prim::Constant(), scope: torch.nn.modules.container.Sequential::/ultralytics.nn.tasks.DetectionModel::0/ultralytics.nn.modules.block.HGStem::model.0
    )  (type 'NoneType')
    Outputs:
        #0: input.4 defined in (%input.4 : Float(*, *, *, *, strides=[3297312, 103041, 321, 1], requires_grad=0, device=cpu) = onnx::Pad[mode="constant"](%449, %476, %452), scope: torch.nn.modules.container.Sequential::/ultralytics.nn.tasks.DetectionModel::0/ultralytics.nn.modules.block.HGStem::model.0 # /opt/nvidia/deepstream/ultralytics/ultralytics/nn/modules/block.py:114:0
    )  (type 'Tensor')

My environment is:

onnx                     1.16.2
onnxruntime              1.18.1
onnxsim                  0.4.36

@prashant-dn
Copy link

When I try to export with a custom size
python3 rtdetr_export.py -w best.pt -s 384 640 --simplify --dynamic
It works

@marcoslucianops
Copy link
Owner

Use different torch version.

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