如何将 onnx 模型转换为 tensorflow 保存的模型? [英] How could I convert onnx model to tensorflow saved model?

查看:83
本文介绍了如何将 onnx 模型转换为 tensorflow 保存的模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 tf-serving 来部署我的火炬模型.我已将我的火炬模型导出到 onnx.如何为 tf-serving 生成 pb 模型?

I am trying to use tf-serving to deploy my torch model. I have exported my torch model to onnx. How could I generate the pb model for tf-serving ?

推荐答案

使用 onnx/onnx-tensorflow 转换器工具作为 ONNX 的 Tensorflow 后端.

Use the onnx/onnx-tensorflow converter tool as a Tensorflow backend for ONNX.

  1. 安装 onnx-tensorflow:pip install onnx-tf

使用命令行工具进行转换:onnx-tf 转换 -t tf -i/path/to/input.onnx -o/path/to/output.pb

Convert using the command line tool: onnx-tf convert -t tf -i /path/to/input.onnx -o /path/to/output.pb

或者,您可以通过 python API 进行转换.

Alternatively, you can convert through the python API.

import onnx

from onnx_tf.backend import prepare

onnx_model = onnx.load("input_path")  # load onnx model
tf_rep = prepare(onnx_model)  # prepare tf representation
tf_rep.export_graph("output_path")  # export the model

这篇关于如何将 onnx 模型转换为 tensorflow 保存的模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆