Tream733 / centerpoint-livox

CenterPoint model trained on livox dataset, and deployed with TensorRT on ros2
24 stars 1 forks source link

Cannot transfer .pt to ONNX #6

Closed yaobaishen closed 7 months ago

yaobaishen commented 7 months ago

Hi, I follow the guide to download .pt from livox_detection, but when I try to convert it into ONNX, I encounter below error:

[ERROR] [1711347661.973846]: bad callback: <bound method ros_demo.online_inference of <__main__.ros_demo object at 0x7fc9d5292a00>>
Traceback (most recent call last):
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 750, in _invoke_callback
    cb(msg)
  File "test_ros.py", line 222, in online_inference
    torch.onnx.export(self.model_wo_nms,
  File "/home/nsoft/anaconda3/envs/livox_sdk/lib/python3.8/site-packages/torch/onnx/__init__.py", line 271, in export
    return utils.export(model, args, f, export_params, verbose, training,
  File "/home/nsoft/anaconda3/envs/livox_sdk/lib/python3.8/site-packages/torch/onnx/utils.py", line 88, in export
    _export(model, args, f, export_params, verbose, training, input_names, output_names,
  File "/home/nsoft/anaconda3/envs/livox_sdk/lib/python3.8/site-packages/torch/onnx/utils.py", line 694, in _export
    _model_to_graph(model, args, verbose, input_names,
  File "/home/nsoft/anaconda3/envs/livox_sdk/lib/python3.8/site-packages/torch/onnx/utils.py", line 463, in _model_to_graph
    graph = _optimize_graph(graph, operator_export_type,
  File "/home/nsoft/anaconda3/envs/livox_sdk/lib/python3.8/site-packages/torch/onnx/utils.py", line 206, in _optimize_graph
    graph = torch._C._jit_pass_onnx(graph, operator_export_type)
  File "/home/nsoft/anaconda3/envs/livox_sdk/lib/python3.8/site-packages/torch/onnx/__init__.py", line 309, in _run_symbolic_function
    return utils._run_symbolic_function(*args, **kwargs)
  File "/home/nsoft/anaconda3/envs/livox_sdk/lib/python3.8/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 "/home/nsoft/anaconda3/envs/livox_sdk/lib/python3.8/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 "/home/nsoft/anaconda3/envs/livox_sdk/lib/python3.8/site-packages/torch/onnx/symbolic_registry.py", line 116, in get_registered_op
    raise RuntimeError(msg)
RuntimeError: Exporting the operator __iand_ to ONNX opset version 11 is not supported. Please feel free to request support or submit a pull request on PyTorch GitHub.

So looks like besides of the atan2() is not supported by ONNX, the above __iand__ operator is not supported too. After debugging, the operator is implicitly called by CenterHead::decode_bbox_from_heatmap(), I have looked through the code, still has no idea how to workaround it. Could you share your experience how to convert the .pt to ONNX file? Thanks a lot.

yaobaishen commented 7 months ago

Finally work it out, here is the solution:

original code:  mask &= xxx
new code:       mask = mask & xxx
yaobaishen commented 7 months ago

close the topic