tensorflow-onnx icon indicating copy to clipboard operation
tensorflow-onnx copied to clipboard

fail to run tf2 example.

Open hellc3c opened this issue 2 years ago • 2 comments

I want to convert a tf2 model to onnx, but it report a error.I go back to run example of convert a pretrained resnet50 model to test my usage. I run the notebook, the first way using scripts to convert running successfully, but the command line approach failed. the reported error are the same as my encountered when i convert my own model. how someone familiar with tf2onnx can help me with this. Describe the bug

2023-03-01 14:31:35,400 - WARNING - '--tag' not specified for saved_model. Using --tag serve 2023-03-01 14:31:38,317 - INFO - Signatures found in model: [serving_default]. 2023-03-01 14:31:38,318 - WARNING - '--signature_def' not specified, using first signature: serving_default 2023-03-01 14:31:38,318 - INFO - Output names: ['predictions'] Traceback (most recent call last): File "convert.py", line 706, in main() File "convert.py", line 238, in main graph_def, inputs, outputs, initialized_tables, tensors_to_rename = tf_loader.from_saved_model( File "/home/hellc/miniconda3/envs/test/lib/python3.8/site-packages/tf2onnx/tf_loader.py", line 611, in from_saved_model _from_saved_model_v2(model_path, input_names, output_names, File "/home/hellc/miniconda3/envs/test/lib/python3.8/site-packages/tf2onnx/tf_loader.py", line 595, in _from_saved_model_v2 frozen_graph, initialized_tables = from_trackable(imported, concrete_func, inputs, outputs, large_model) File "/home/hellc/miniconda3/envs/test/lib/python3.8/site-packages/tf2onnx/tf_loader.py", line 229, in from_trackable _get_hash_table_info_from_trackable(trackable, table_info, File "/home/hellc/miniconda3/envs/test/lib/python3.8/site-packages/tf2onnx/tf_loader.py", line 464, in _get_hash_table_info_from_trackable for t in r.dict.values() if hasattr(r, 'dict') else []: File "/home/hellc/miniconda3/envs/test/lib/python3.8/site-packages/tensorflow/python/training/tracking/data_structures.py", line 828, in getattribute return super(_DictWrapper, self).getattribute(name) TypeError: this dict descriptor does not support '_DictWrapper' objects Urgency

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 18.04*): Unbuntu 22.04
  • TensorFlow Version: 2.7.0
  • Python version: 3.8.15
  • ONNX version (if applicable, e.g. 1.11*): 1.13.1
  • ONNXRuntime version (if applicable, e.g. 1.11*):1.14.1
  • tf2onnx: 1.13.0

To Reproduce

just run the notebook, the command line part goes wrong. Screenshots

image image

Additional context

hellc3c avatar Mar 01 '23 06:03 hellc3c

Hey @hellc3c , could you check which version of the package wrapt is installed? I had the same issue using tf2onnx for model optimizing. The problem came out of no where, as the same code worked only days before. I pinned the problem down to one unfreezed dependency (I think in tensorflow).
You should be able to solve the problem by installing wrapt in version 1.14.1, while tensorflow would install the most recent version 1.15.0 by default. pip install wrapt==1.14.1 I'd be happy to hear if i could help you.

And for the team: Maybe you could add the requirement for wrapt being < 1.15 till this is fixed from tensorflow or wrapt.

Background:

I am using tf2onnx in a Databricks environment to optimize tf models by converting them to onnx. Had the same issue with the following requirements:

opencv-python==4.7.0.68 segmentation-models==1.0.1 tensorflow==2.7.4 numpy ==1.24.2 tensorflow-addons==0.15.0 pandas==1.3.5 Pillow==9.4.0 scikit-image==0.18.3 tqdm==4.62.3 fire==0.5.0 tf2onnx==1.12.1

File "/databricks/conda/envs/mlflow-.../lib/python3.8/site-packages/tensorflow/python/training/tracking/data_structures.py", line 828, in __getattribute__ return super(_DictWrapper, self).__getattribute__(name) TypeError: this __dict__ descriptor does not support '_DictWrapper' objects

By adding the requirement wrapt==1.14.1 I was able to solve this issue

julianstrietzel avatar Mar 06 '23 08:03 julianstrietzel

Please try to upgrade tensorflow to 2.8.0 or above, this issue will also be fixed.

fatcat-z avatar Mar 07 '23 09:03 fatcat-z