onnx / tensorflow-onnx

Convert TensorFlow, Keras, Tensorflow.js and Tflite models to ONNX
Apache License 2.0
2.31k stars 433 forks source link

AttributeError: 'FuncGraph' #2238

Open ashtarimo opened 1 year ago

ashtarimo commented 1 year ago

Hi,

I am using the below command to convert a tf-nlp model to onnx. It has a custom-ops built in.

!/anaconda/envs/onnxet/bin/python3.10 -m tf2onnx.convert --saved-model {checkpoint_path} --output {onnx_model_output_path} --extra_opset ai.onnx.contrib:1 --custom-ops StringStrip:ai.onnx.contrib

The code has been working fine with no issue, but for some reason, not anymore. Here is the error I get:

Execute tf2onnx.convert from saved model ./01_nlprrs_pg_01_NoGmail_tf/ to output nlprrs_pg_NoTop20.onnx /anaconda/envs/onnxet/lib/python3.10/runpy.py:126: RuntimeWarning: 'tf2onnx.convert' found in sys.modules after import of package 'tf2onnx', but prior to execution of 'tf2onnx.convert'; this may result in unpredictable behaviour warn(RuntimeWarning(msg)) 2023-09-14 05:38:25,073 - WARNING - '--tag' not specified for saved_model. Using --tag serve 2023-09-14 05:38:25,996 - INFO - Signatures found in model: [serving_default]. 2023-09-14 05:38:25,997 - WARNING - '--signature_def' not specified, using first signature: serving_default Traceback (most recent call last): File "/anaconda/envs/onnxet/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/anaconda/envs/onnxet/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/anaconda/envs/onnxet/lib/python3.10/site-packages/tf2onnx/convert.py", line 706, in main() File "/anaconda/envs/onnxet/lib/python3.10/site-packages/tf2onnx/convert.py", line 238, in main graph_def, inputs, outputs, initialized_tables, tensors_to_rename = tf_loader.from_saved_model( File "/anaconda/envs/onnxet/lib/python3.10/site-packages/tf2onnx/tf_loader.py", line 611, in from_saved_model _from_saved_model_v2(model_path, input_names, output_names, File "/anaconda/envs/onnxet/lib/python3.10/site-packages/tf2onnx/tf_loader.py", line 573, in _from_saved_model_v2 graph_captures = concrete_func.graph._captures # pylint: disable=protected-access AttributeError: 'FuncGraph' object has no attribute '_captures'. Did you mean: 'captures'?

I would appreciate any advice. Mo

fatcat-z commented 1 year ago

Could you please try the latest tf2onnx version? This is an issue brought by recent TensorFlow versions and was fixed already.