简体   繁体   English

尝试使用 onnx-tf 库将 .onnx 模型转换为 .pb 模型

[英]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.我试图通过使用onnx-tf包将.onnx模型转换为.pb格式,但是,在调用onnx_tf.backend.prepare函数后,python 内核崩溃了。 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模型时会导致不同的错误,如下所示:

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.但是,根据 Github 页面,依赖项似乎是正确的。

There were large changes between ONNX 1.6 and 1.7 that caused many dependency issues. ONNX 1.6 和 1.7 之间的巨大变化导致了许多依赖性问题。 Try with Onnx 1.6, which may be the source of your issue.尝试使用 Onnx 1.6,这可能是您问题的根源。 Where did you find 1.7 mentioned as the required version?您在哪里找到提到的 1.7 作为所需版本?

Additionally, you mention the Python kernel crashing?此外,您提到 Python 内核崩溃? Are you running in a Jupyter notebook?你在 Jupyter 笔记本上运行吗?

I've found this package to be a lot more unstable in Juypter notebook, and not print out all of the relevant errors.我发现这个包在 Juypter 笔记本中更加不稳定,并且没有打印出所有相关错误。 If you could test your system in a standalone Python script you may get more information.如果您可以在独立的 Python 脚本中测试您的系统,您可能会获得更多信息。

Importing onnx and onnx-tf related libraries before tf and pytorch should help.tfpytorch之前导入onnxonnx-tf相关库应该会有所帮助。 The problem is probably caused by a version clash since both onnx and onnx-tf use tf .该问题可能是由版本冲突引起的,因为onnxonnx-tf使用tf

Can you install onnx-tf of this commit 7d8fa7d88fab469253d75e5e11cf9cdcb90104c4你能安装这个提交的 onnx-tf 7d8fa7d88fab469253d75e5e11cf9cdcb90104c4

Between order of imports and this commit the issue was solved for me在导入顺序和此提交之间,问题已为我解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM