pythontensorflowtensorflow-liteonnxtf2onnx

Convert TensorFlow to ONNX: Current implementation of RFFT or FFT only allows ComplexAbs as consumer not {'Imag', 'Real'}


I am trying to convert this TensorFlow model to onnx. But I get an error message:

> python -m tf2onnx.convert --saved-model .\spice --output model.onnx --opset 11 --verbose
...
2023-04-08 18:33:10,811 - ERROR - tf2onnx.tfonnx: Tensorflow op [Real: Real] is not supported
2023-04-08 18:33:10,812 - ERROR - tf2onnx.tfonnx: Tensorflow op [Imag: Imag] is not supported
2023-04-08 18:33:10,879 - ERROR - tf2onnx.tfonnx: Unsupported ops: Counter({'Real': 6, 'Imag': 6})
...
ValueError: make_sure failure: Current implementation of RFFT or FFT only allows ComplexAbs as consumer not {'Real', 'Imag'}

Same happens with the TensorFlow Light (tflight) model:

> python -m tf2onnx.convert --opset 16 --tflite .\lite-model_spice_1.tflite --output spice.onnx
...
ValueError: make_sure failure: Current implementation of RFFT or FFT only allows ComplexAbs as consumer not {'Imag', 'Real'}

I am on Windows 11, Python 3.10.10, TensorFlow 2.12

This is my first attempt with TensorFlow / ONNX, so I am unsure where the error comes from.

Questions


Solution

    1. The error mentioned above occurred because tf2onnx does not support Real and Imag operations. For a list of operations that can be used with tf2onnx, please refer to this link. This will also affect the TensorFlow model.
    2. I'm not sure what this means, but as far as I know, it has no relation whatsoever to what is referred to in point number 2.
    3. The way to solve this is by changing the Real and Imag operations as follows:
    # Compute the real and imaginary components using tf.math.real and tf.math.imag
    x_real = tf.math.real(x)
    x_imag = tf.math.imag(x)