keras-onnx
keras-onnx copied to clipboard
Unrecognized attribute: axes for operator Squeeze/RecduceSum
System information
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Ubuntu 16.04
- ONNX Runtime installed from (source or binary): pip
- ONNX Runtime version: 1.7.0
- Python version: 3.6.8
- Visual Studio version (if applicable):
- GCC/Compiler version (if compiling from source):
- CUDA/cuDNN version:
- GPU model and memory:
To Reproduce
- Describe steps/code to reproduce the behavior.
- convert
h5model created by tf.keras(tf1.12) to ONNX with code:
onnx_model = keras2onnx.convert_keras(model, model.name, target_opset=13, debug_mode=False)
- load onnx_model into sess:
sess = onnxruntime.InferenceSession(onnx_model.SerializeToString())
- then step 2 report error like this:
Traceback (most recent call last):
File "trans_model_format.py", line 85, in <module>
keras_model_to_onnx(file_path)
File "trans_model_format.py", line 49, in keras_model_to_onnx
sess = onnxruntime.InferenceSession(onnx_model.SerializeToString())
File "/home/zhanshen/.local/lib/python3.6/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 280, in __init__
self._create_inference_session(providers, provider_options)
File "/home/zhanshen/.local/lib/python3.6/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 309, in _create_inference_session
sess = C.InferenceSession(session_options, self._model_bytes, False, self._read_config_from_model)
onnxruntime.capi.onnxruntime_pybind11_state.InvalidGraph: [ONNXRuntimeError] : 10 : INVALID_GRAPH : This is an invalid model. Error in Node:cos_sim/einsum/Shape:0_squeeze : Unrecognized attribute: axes for operator Squeeze
In my model build code with tf.keras, there is a tf.einsum op for calculating cosine sim.
And if I use tf.keras.layers.Dot layer to calculate cosine sim, the h5 model was also converted successfully and report cos_sim/dot/l2_normalize_1/Sum_reduce_min : Unrecognized attribute: axes for operator ReduceSum when loading onnx_model to sess
Before this, I opened microsoft/onnxruntime#7338.
This converter has worked for me. Although you have to train your model in tensorflow version 2.2, it might not work in other versions. https://github.com/onnx/onnxmltools