Search code examples
tensorflowonnxtf2onnx

Which AI models can be converted to ONNX?


I think in theory, every (TensorFlow) model can be converted to ONNX because at some level it is a pretty basic neural network graph. Is this assumption correct?

But I found that there are limitations in practice. For instance, I found that the conversion of this model to ONNX fails when using tf2onnx (v1.14.0) with the following error message:

ValueError: make_sure failure: Current implementation of RFFT or FFT only allows ComplexAbs as consumer not {'Imag', 'Real'}
2023-04-04 09:30:26,364 - ERROR - Tensorflow op [Real: Real] is not supported
2023-04-04 09:30:26,364 - ERROR - Tensorflow op [Imag_5: Imag] is not supported

Questions:

  • Is it possible to simplify above model (and models in general) such that it can be converted to ONNX?
  • Can a pretrained model (e.g. from TensorFlow Hub) be simplified or is its original training data necessary?

Solution

  • Converting models in ONNX isn't as straightforward as you think. And as @oleg-kostromin specified it depends if all the operators in your original framework have an equivalent in ONNX. I recommend changing the opset see here to a higher version during conversion, and see if that resolves the issue. Otherwise, you can either remove the layers that are causing the conversion errors manually using graph-surgeon or write your own operator.