wprazuch
wprazuch

Reputation: 101

Trying to convert .onnx model to .pb model using onnx-tf library

I am trying to convert .onnx model to .pb format by using onnx-tf package, however, after invoking onnx_tf.backend.prepare function, the python kernel crashes. I am using the code below:

import onnx

from onnx_tf.backend import prepare
import tensorflow
onnx_model = onnx.load(<path-to-model>)  # load onnx model
tf_rep = prepare(onnx_model)  # <------ That's where python crashes
tf_rep.export_graph(<output-path>)  # export the model

I have double-checked package version dependencies, as wrong dependencies caused different errors while loading the .onnx model, and those are as follows:

onnx==1.7.0
onnx-tf==1.6.0
tensorflow==2.2.0
tensorflow-addons==0.10.0
torch==1.6.0+cu101

However, the dependencies seem to be correct, according to Github pages.

Upvotes: 0

Views: 3383

Answers (3)

Prasanna Kumar R
Prasanna Kumar R

Reputation: 1

Can you install onnx-tf of this commit 7d8fa7d88fab469253d75e5e11cf9cdcb90104c4

Between order of imports and this commit the issue was solved for me

Upvotes: 0

Prasanna Kumar R
Prasanna Kumar R

Reputation: 1

Importing onnx and onnx-tf related libraries before tf and pytorch should help. The problem is probably caused by a version clash since both onnx and onnx-tf use tf.

Upvotes: 0

Prunus Persica
Prunus Persica

Reputation: 1203

There were large changes between ONNX 1.6 and 1.7 that caused many dependency issues. Try with Onnx 1.6, which may be the source of your issue. Where did you find 1.7 mentioned as the required version?

Additionally, you mention the Python kernel crashing? Are you running in a Jupyter notebook?

I've found this package to be a lot more unstable in Juypter notebook, and not print out all of the relevant errors. If you could test your system in a standalone Python script you may get more information.

Upvotes: 1

Related Questions