onnx-tensorflow
onnx-tensorflow copied to clipboard
'_UserObject' object has no attribute 'summary'
Hello,
I converted my onnx model to a tensorflow model('saved_model'
in the code) using you library. It's successfully done. But in the following piece of code when I used the tensorflow model, I got an error:
import os
import tensorflow as tf
New_Model = tf.keras.models.load_model('saved_model')
print(New_Model.summary())
Error:
2021-01-20 14:21:03.384188: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2021-01-20 14:21:03.384218: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-01-20 14:21:04.649847: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2021-01-20 14:21:04.649893: W tensorflow/stream_executor/cuda/cuda_driver.cc:312] failed call to cuInit: UNKNOWN ERROR (303)
2021-01-20 14:21:04.649934: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (persia): /proc/driver/nvidia/version does not exist
2021-01-20 14:21:04.650115: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-01-20 14:21:04.674624: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 2599990000 Hz
2021-01-20 14:21:04.674953: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x46edd10 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-01-20 14:21:04.674995: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
Traceback (most recent call last):
File "tensorflow-keras.py", line 6, in <module>
print(New_Model.summary())
AttributeError: '_UserObject' object has no attribute 'summary
Tensorflow version = 2.3.1 Python version = 3.6.9 onnx-tf version = 1.7.0 digits.onnx.tar.gz
Please note the saved_model is persisted using the low-level API. So you need to use tf.saved_model.load(path_to_dir) to load, rather than the high level tf.keras.models.load_model('saved_model')
Thanks, @chinhuang007 for your answer.
I tried tf.saved_model.load(path_to_dir)
for loading the tf model but I still get the same error.
I just downloaded your onnx file and ran the following with no errors.
import onnx_tf
import onnx
import tensorflow as tf
onnx_path = 'digits.onnx'
model_path = 'digits_savedmodel'
model = onnx.load(onnx_path)
# convert and save the model
tf_rep = onnx_tf.backend.prepare(model, logging_level="WARN", auto_cast=True)
tf_rep.export_graph(model_path)
# load the saved_model using low-level API
m = tf.saved_model.load(model_path)
print(m)
print('loaded model inputs = ', m.signatures['serving_default'].inputs)
print('loaded model outputs = ', m.signatures['serving_default'].outputs)
I got the same error with both tf.keras.models.load_model
and tf.saved_model.load
. And my tensorflow version = 2.4.1, onnx-tf version = 1.7.0. May I have any advice? Thx!
Same here, what's more, I got a WARNING message when converting WARNING:absl:Found untraced functions such as gen_tensor_dict while saving (showing 1 of 1). These functions will not be directly callable after loading.
Same as @chamboin
Same here, what's more, I got a WARNING message when converting
WARNING:absl:Found untraced functions such as gen_tensor_dict while saving (showing 1 of 1). These functions will not be directly callable after loading.
You can downgrade tf to 2.3 and the warning does not show up. How to use the file: https://github.com/onnx/onnx-tensorflow/issues/901#issuecomment-821686852
Thank you so much @AndyMcPython - downgrading from 2.5.0 to 2.3.0 fixed the issue for me. The time to convert to savedmodel also decreased significantly. Same issue with AttributeError: '_UserObject' object has no attribute 'summary'
though.