3

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

  • Is it related to TensorFlow, tf2onnx, or the model?
  • Would it work with another setup (maybe on Linux or other TF version)?
  • How to fix the issue?
mihca
  • 997
  • 1
  • 10
  • 29
  • Tested it on Linux (WSL), makes no difference – mihca Apr 07 '23 at 16:41
  • 1
    The error message indicates that the tf2onnx converter does not support the TensorFlow model's Real and Imag operations. These operations are used to calculate the real and imaginary components of a complex number. To resolve this issue, consider replacing the model's Real and Imag operations with equivalent TensorFlow operations supported by the tf2onnx converter like using tf.math.real and tf.math.imag. The tf.math.real and tf.math.imag operations, which compute the real and imaginary components of a complex number, are one technique. – Panji Tri Wahyudi Apr 25 '23 at 09:32

1 Answers1

2
  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)
  • I see, this is unexpected. I expected models to be converted to ONNX at a lower level such that is works for every trained neural network. – mihca Apr 26 '23 at 06:39
  • Do I need to re-train the model to change real and imag operations? I expect this to involve (a) change model's code as you suggest and then (b) train the modified model with same data? – mihca Apr 26 '23 at 06:41
  • Is this possible with a SavedModel that I downloaded from TensorFlow Hub? – mihca Apr 26 '23 at 06:50