tensorflow-onnx icon indicating copy to clipboard operation
tensorflow-onnx copied to clipboard

tf2onnx failed to convert ComplexAbs with opset 15

Open yjiangling opened this issue 8 months ago • 0 comments

When I convert a TensorFlow model to onnx with opset 15, it gives the following error,

2024-06-13 02:14:58,205 - INFO - Using tensorflow=2.12.0, onnx=1.16.1, tf2onnx=1.16.1/15c810
2024-06-13 02:14:58,205 - INFO - Using opset <onnx, 15>
2024-06-13 02:14:59,114 - INFO - Apply shape override:
2024-06-13 02:14:59,114 - INFO - 	Set xs:0 shape to [1, None]
2024-06-13 02:14:59,114 - INFO - 	Set xlen:0 shape to [1]
2024-06-13 02:15:00,333 - INFO - Computed 0 values for constant folding
2024-06-13 02:15:02,241 - ERROR - Failed to convert node 'PartitionedCall/PartitionedCall/Abs' (fct=<bound method ComplexAbsOp.version_13 of <class 'tf2onnx.onnx_opset.signal.ComplexAbsOp'>>)
'OP=ComplexAbs\nName=PartitionedCall/PartitionedCall/Abs\nInputs:\n\tCPLX_Reshape_PartitionedCall/PartitionedCall/rfftrfft__66:0=Reshape, [-1, -1, -1, -1], 1\nOutpus:\n\tPartitionedCall/PartitionedCall/Abs:0=[-1, -1, 257], 1'
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/onnx_opset/signal.py", line 981, in version_13
    cls.any_version(13, ctx, node, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/onnx_opset/signal.py", line 939, in any_version
    utils.make_sure(
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/utils.py", line 303, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: ComplexAbs expected the first dimension to be 2 but shape is [-1, -1, -1, -1]
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/convert.py", line 714, in <module>
    main()
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/convert.py", line 273, in main
    model_proto, _ = _convert_common(
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/convert.py", line 168, in _convert_common
    g = process_tf_graph(tf_graph, const_node_values=const_node_values,
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/tfonnx.py", line 464, in process_tf_graph
    g = process_graphs(main_g, subgraphs, custom_op_handlers, inputs_as_nchw, outputs_as_nchw, continue_on_error,
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/tfonnx.py", line 516, in process_graphs
    g = process_parsed_graph(main_g, custom_op_handlers, inputs_as_nchw, outputs_as_nchw, continue_on_error,
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/tfonnx.py", line 627, in process_parsed_graph
    raise exceptions[0]
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/tfonnx.py", line 292, in tensorflow_onnx_mapping
    func(g, node, **kwargs, initialized_tables=initialized_tables, dequantize=dequantize)
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/onnx_opset/signal.py", line 981, in version_13
    cls.any_version(13, ctx, node, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/onnx_opset/signal.py", line 939, in any_version
    utils.make_sure(
  File "/usr/local/lib/python3.10/dist-packages/tf2onnx/utils.py", line 303, in make_sure
    raise ValueError("make_sure failure: " + error_msg % args)
ValueError: make_sure failure: ComplexAbs expected the first dimension to be 2 but shape is [-1, -1, -1, -1]

But when I change the opset to 13, it works fine. And I read the support status readme file, it seems the ComplexAbs con be converted with opset 1~18. What's wrong? Anyone can give some help? Thanks a lot. By the way, the operation in TensorFlow is designed like this:

tf.math.abs(tf.signal.rfft(framed_signals, [fft_length]))

yjiangling avatar Jun 13 '24 03:06 yjiangling