Which AI models can be converted to ONNX?

656 Views Asked by At

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?
2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On

In principle any model can be converted to onnx as long as it can be represented by the available ONNX operators. However, this is not always the case.

If you are using onnxruntime for inference, it is actually possible to create and register custom operators using either C++ or Python.

https://onnxruntime.ai/docs/reference/operators/add-custom-op.html

https://github.com/microsoft/onnxruntime-extensions/blob/main/tutorials/tf2onnx_custom_ops_tutorial.ipynb