首页 > 解决方案 > 如何将 onnx 模型转换为 tensorflow 保存的模型?

问题描述

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

标签: tensorflowtensorflow-servingonnx

解决方案


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

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

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

或者,您可以通过 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

推荐阅读