I tried python -m tf2onnx.convert --saved-model [file_name] --output [onnx_file_name]
. but It is run by tensorflow = 2.4.4
automatically.
I want to run tensorflow version 1 code. Is this code have a option of it?

- 41
- 4
4 Answers
I used python -m tf2onnx.convert --saved-model [model file] --output [onnx file name].onnx --opset 13
and I solved it.

- 41
- 4
You can install TensorFlow version 1, I also trying to use tf.compat.v1.layers that also work with the result . You may need to use model.save to have .pb format and convert by the program.

- 4,555
- 31
- 31
- 45

- 736
- 6
- 9
I also had similar problem and solved by following above seawavve and Jirayu suggestion: python -m tf2onnx.convert --saved-model <PB file folder> --output <output file>
I had generated the PB file in Python 3.6 and Tensorflow 1.15, but I had to generate the ONNX file in Python 3.8 ("tf2onnx" not supporting Python 3.6). This restriction required uninstall and install a few software dependencies:
Installed
tensorflow-gpu==2.2.0
tf2onnx==1.12.1
and downgraded
protobuf==3.20.2
numpy==1.20
and installed (I faced an error on above command line)
packaging
By the way, the PB file was generated with unfreeze option.
Runtime environment:
Ubuntu 20.04

- 1,594
- 19
- 22
I was able to convert .pb(tensorflow 1 model) files to tf2 saved model by using this package called openvino2tensorflow link
Follow pb_to_saved_model documentation here and convert it to saved model format.
Then you can use the saved model directory to provide to tf2onnx and get it converted to onnx.

- 175
- 1
- 13