tensorflow-onnx
tensorflow-onnx copied to clipboard
UnicodeDecodeError both ascii and utf-8
Describe the bug I believe I'm getting the same error as Meimin-Wang is in issue #1913.
I run:
python -m tf2onnx.convert --opset 15 --input frozen_inference_graph.pb --output frozen_inference_graph.onnx --inputs encoded_image_string_tensor:0 --outputs detection_boxes:0,detection_scores:0,detection_classes:0,num_detections:0
I get:
2022-05-03 09:57:22.427771: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2022-05-03 09:57:22.429113: 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.
/usr/lib/python3.8/runpy.py:127: 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))
2022-05-03 09:57:24.677304: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory
2022-05-03 09:57:24.677952: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303)
2022-05-03 09:57:24.678540: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (TORLOFC1347): /proc/driver/nvidia/version does not exist
2022-05-03 09:57:24.679882: I tensorflow/core/platform/cpu_feature_guard.cc:151] 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.
WARNING:tensorflow:From /home/ebaum/.local/lib/python3.8/site-packages/tf2onnx/tf_loader.py:305: convert_variables_to_constants (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.compat.v1.graph_util.convert_variables_to_constants`
2022-05-03 09:57:27,367 - WARNING - From /home/ebaum/.local/lib/python3.8/site-packages/tf2onnx/tf_loader.py:305: convert_variables_to_constants (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.compat.v1.graph_util.convert_variables_to_constants`
WARNING:tensorflow:From /home/ebaum/.local/lib/python3.8/site-packages/tensorflow/python/framework/convert_to_constants.py:925: extract_sub_graph (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.compat.v1.graph_util.extract_sub_graph`
2022-05-03 09:57:27,373 - WARNING - From /home/ebaum/.local/lib/python3.8/site-packages/tensorflow/python/framework/convert_to_constants.py:925: extract_sub_graph (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.compat.v1.graph_util.extract_sub_graph`
2022-05-03 09:57:27.873643: I tensorflow/core/grappler/devices.cc:66] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0
2022-05-03 09:57:27.875350: I tensorflow/core/grappler/clusters/single_machine.cc:358] Starting new session
2022-05-03 09:57:29.667601: I tensorflow/core/grappler/optimizers/meta_optimizer.cc:1164] Optimization results for grappler item: graph_to_optimize
constant_folding: Graph size after: 2092 nodes (-1611), 2754 edges (-1806), time = 501.62ms.
function_optimizer: function_optimizer did nothing. time = 0.022ms.
constant_folding: Graph size after: 2092 nodes (0), 2754 edges (0), time = 517.377ms.
function_optimizer: function_optimizer did nothing. time = 0.019ms.
2022-05-03 09:57:32,860 - INFO - Using tensorflow=2.8.0, onnx=1.11.0, tf2onnx=1.10.0/4d8d59
2022-05-03 09:57:32,861 - INFO - Using opset <onnx, 15>
Traceback (most recent call last):
File "/home/ebaum/.local/lib/python3.8/site-packages/tf2onnx/tf_utils.py", line 58, in tf_to_onnx_tensor
np_data = np_data.astype(np.str).astype(np.object)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/ebaum/.local/lib/python3.8/site-packages/tf2onnx/convert.py", line 640, in <module>
main()
File "/home/ebaum/.local/lib/python3.8/site-packages/tf2onnx/convert.py", line 266, in main
model_proto, _ = _convert_common(
File "/home/ebaum/.local/lib/python3.8/site-packages/tf2onnx/convert.py", line 161, in _convert_common
g = process_tf_graph(tf_graph, const_node_values=const_node_values,
File "/home/ebaum/.local/lib/python3.8/site-packages/tf2onnx/tfonnx.py", line 433, in process_tf_graph
main_g, subgraphs = graphs_from_tf(tf_graph, input_names, output_names, shape_override, const_node_values,
File "/home/ebaum/.local/lib/python3.8/site-packages/tf2onnx/tfonnx.py", line 448, in graphs_from_tf
ordered_func = resolve_functions(tf_graph)
File "/home/ebaum/.local/lib/python3.8/site-packages/tf2onnx/tf_loader.py", line 764, in resolve_functions
_, _, _, _, _, functions = tflist_to_onnx(tf_graph, {})
File "/home/ebaum/.local/lib/python3.8/site-packages/tf2onnx/tf_utils.py", line 441, in tflist_to_onnx
onnx_tensor = tf_to_onnx_tensor(value, name=port_name(node.name))
File "/home/ebaum/.local/lib/python3.8/site-packages/tf2onnx/tf_utils.py", line 61, in tf_to_onnx_tensor
np_data = decode(np_data).astype(np.object)
File "/home/ebaum/.local/lib/python3.8/site-packages/numpy/lib/function_base.py", line 2304, in __call__
return self._vectorize_call(func=func, args=vargs)
File "/home/ebaum/.local/lib/python3.8/site-packages/numpy/lib/function_base.py", line 2382, in _vectorize_call
ufunc, otypes = self._get_ufunc_and_otypes(func=func, args=args)
File "/home/ebaum/.local/lib/python3.8/site-packages/numpy/lib/function_base.py", line 2342, in _get_ufunc_and_otypes
outputs = func(*inputs)
File "/home/ebaum/.local/lib/python3.8/site-packages/tf2onnx/tf_utils.py", line 60, in <lambda>
decode = np.vectorize(lambda x: x.decode('UTF-8'))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
I created a short script substantially the same as Meimin-Wangs and attempted to open the pb file with with open(model_file, encoding="utf8", errors='ignore') as f: as suggested by fatcat-z but I get the error TypeError: a bytes-like object is required, not 'str'. Trying to convert this with bytes(f.read(), encoding = 'utf8')' (well, the equivalent with different variable names) gives me
Traceback (most recent call last):
File "to-onnx.py", line 28, in <module>
graph_def.ParseFromString(bytes(serialized_graph, encoding = 'utf8'))
google.protobuf.message.DecodeError: Error parsing message with type 'tensorflow.GraphDef'
I have, as you see, tried the lateset opset. I've installed tensorflow-onnx from https://github.com/onnx/tensorflow-onnx. My model was created in TF1. I didn't run in a venv (because you can't install TF1 from PyPI with python 3.8), but I created an conda environment with TF 1.15 and that didn't work either. I end up with the same UnicodeDecodeErrors. I primarily tried to get this to work in a WSL 1 instance running Ubuntu 20.04.4 LTS but I have also tried to run it natively on the WIndows 10 Enterprise version 1909 build 18363.2158 machine which it is hosted on to the same results.
Urgency Close to None, but things will heat up in a couple months. Call it 7/3/2022.
System information
- OS Platform and Distribution: WSL 1 instance running Ubuntu 20.04.4 LTS and WIndows 10 Enterprise version 1909 build 18363.2158
- Tensorflow Version: 2.8 and 1.15
- Python version: 3.8 and 3.7
To Reproduce Just run the command line above, which you can't do because unfortunately I can't share the model. I'm not even completely sure of its initial source, but I believe it's a modified form of the ssd_resnet_50_fpn_coco ☆ from the TensorFlow object_detection model zoo.
Could you please share the code of to-onnx.py file? It should not be sensitive, right?
Or, could you please try the command below to see if it works?
python -m tf2onnx.convert --opset 15 --saved-model frozen_inference_graph.pb --output frozen_inference_graph.onnx --inputs encoded_image_string_tensor:0 --outputs detection_boxes:0,detection_scores:0,detection_classes:0,num_detections:0
It's been over 3 months, so closing this. Feel free to open a new one if the issue still exists.