Install onnx-tensorflow: pip install onnx-tf
Convert using the command line tool: onnx-tf convert -t tf -i /path/to/input.onnx -o /path/to/output.pb
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
Below is the command to convert a TensorFlow 1.0 checkpoint file to ONNX. Notice that you need to find the meta file and pass it to tf2onnx. You also need to specify the input name and the output name.
python -m tf2onnx.convert --checkpoint ./tensorflow/tensorflow_model.ckpt.meta --output tfmodel.onnx --inputs input:0 --outputs output:0
Below is the command to convert a TensorFlow 2.0 model. You need to specify the directory that was used to save the model to disk. (It is not saved in a single file.) You also need to specify the ONNX output file. You do not need to specify the input name and the output name.
python -m tf2onnx.convert --saved-model ./tensorflow --output tfmodel.onnx