I am attempting to use the tf2onnx package and CLI tool to automatically convert a Tensorflow saved_model to ONNX. I was able to do this successfully using a basic model linked in this tutorial; however, I have been unable to convert models produced by GCP BigQueryML, such as this Fraud Detection model.
All attempts on this and other models exported from BQML fail with the error ValueError: Failed to import metagraph, check error log for more info..
Is it possible to convert BQML models to ONNX?
- Python 3.9.16
- tensorflow-cpu 2.15.0
- tf2onnx 1.15.1
Full stack trace:
(vertex-pocs) hrrt@M-C02DM10ZMD6R model % python -m tf2onnx.convert --saved-model cc-defaults --output onnx/cc-defaults.onnx --verbose
2023-12-28 14:21:36.922146: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
/Users/hrrt/.pyenv/versions/3.9.16/lib/python3.9/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))
2023-12-28 14:21:40,108 - WARNING - tf2onnx.tf_loader: '--tag' not specified for saved_model. Using --tag serve
2023-12-28 14:21:40,490 - INFO - tf2onnx.tf_loader: Signatures found in model: [serving_default].
2023-12-28 14:21:40,490 - WARNING - tf2onnx.tf_loader: '--signature_def' not specified, using first signature: serving_default
2023-12-28 14:21:40,490 - INFO - tf2onnx.tf_loader: Output names: ['default_payment_next_month_probs', 'default_payment_next_month_values', 'predicted_default_payment_next_month']
2023-12-28 14:21:40,490 - WARNING - tf2onnx.tf_loader: Could not search for non-variable resources. Concrete function internal representation may have changed.
WARNING:tensorflow:Issue encountered when serializing variables.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
This operation is not supported when eager execution is enabled.
2023-12-28 14:21:40,497 - WARNING - tensorflow: Issue encountered when serializing variables.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
This operation is not supported when eager execution is enabled.
WARNING:tensorflow:Issue encountered when serializing trainable_variables.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
This operation is not supported when eager execution is enabled.
2023-12-28 14:21:40,497 - WARNING - tensorflow: Issue encountered when serializing trainable_variables.
Type is unsupported, or the types of the items don't match field type in CollectionDef. Note this is a warning and probably safe to ignore.
This operation is not supported when eager execution is enabled.
2023-12-28 14:21:40.500445: I tensorflow/core/grappler/devices.cc:75] Number of eligible GPUs (core count >= 8, compute capability >= 0.0): 0 (Note: TensorFlow was not compiled with CUDA or ROCm support)
Traceback (most recent call last):
File "/Users/hrrt/.pyenv/versions/3.9.16/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/Users/hrrt/.pyenv/versions/3.9.16/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/hrrt/.pyenv/versions/vertex-pocs/lib/python3.9/site-packages/tf2onnx/convert.py", line 714, in <module>
main()
File "/Users/hrrt/.pyenv/versions/vertex-pocs/lib/python3.9/site-packages/tf2onnx/convert.py", line 242, in main
graph_def, inputs, outputs, initialized_tables, tensors_to_rename = tf_loader.from_saved_model(
File "/Users/hrrt/.pyenv/versions/vertex-pocs/lib/python3.9/site-packages/tf2onnx/tf_loader.py", line 615, in from_saved_model
_from_saved_model_v2(model_path, input_names, output_names,
File "/Users/hrrt/.pyenv/versions/vertex-pocs/lib/python3.9/site-packages/tf2onnx/tf_loader.py", line 599, in _from_saved_model_v2
frozen_graph, initialized_tables = from_trackable(imported, concrete_func, inputs, outputs, large_model)
File "/Users/hrrt/.pyenv/versions/vertex-pocs/lib/python3.9/site-packages/tf2onnx/tf_loader.py", line 222, in from_trackable
raise e
File "/Users/hrrt/.pyenv/versions/vertex-pocs/lib/python3.9/site-packages/tf2onnx/tf_loader.py", line 218, in from_trackable
frozen_graph = from_function(concrete_func, inputs, outputs, large_model)
File "/Users/hrrt/.pyenv/versions/vertex-pocs/lib/python3.9/site-packages/tf2onnx/tf_loader.py", line 277, in from_function
raise e
File "/Users/hrrt/.pyenv/versions/vertex-pocs/lib/python3.9/site-packages/tf2onnx/tf_loader.py", line 270, in from_function
frozen_func = convert_variables_to_constants_v2(func, lower_control_flow=False, aggressive_inlining=True)
File "/Users/hrrt/.pyenv/versions/vertex-pocs/lib/python3.9/site-packages/tensorflow/python/framework/convert_to_constants.py", line 1164, in convert_variables_to_constants_v2
converter_data = _FunctionConverterDataInEager(
File "/Users/hrrt/.pyenv/versions/vertex-pocs/lib/python3.9/site-packages/tensorflow/python/framework/convert_to_constants.py", line 827, in __init__
graph_def = _run_inline_graph_optimization(func, lower_control_flow,
File "/Users/hrrt/.pyenv/versions/vertex-pocs/lib/python3.9/site-packages/tensorflow/python/framework/convert_to_constants.py", line 1062, in _run_inline_graph_optimization
return tf_optimizer.OptimizeGraph(config, meta_graph)
File "/Users/hrrt/.pyenv/versions/vertex-pocs/lib/python3.9/site-packages/tensorflow/python/grappler/tf_optimizer.py", line 76, in OptimizeGraph
out_graph = optimize_method(
ValueError: Failed to import metagraph, check error log for more info.
