Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Unrecognized attribute: axes for operator Squeeze/RecduceSum #7338

Closed
chan4cc opened this issue Apr 14, 2021 · 4 comments
Closed

Unrecognized attribute: axes for operator Squeeze/RecduceSum #7338

chan4cc opened this issue Apr 14, 2021 · 4 comments
Labels
converter related to ONNX converters

Comments

@chan4cc
Copy link

chan4cc commented Apr 14, 2021

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.
  1. convert h5 model created by tf.keras(tf1.12) to ONNX with code:
onnx_model = keras2onnx.convert_keras(model, model.name, target_opset=13, debug_mode=False)
  1. load onnx_model into sess:
 sess = onnxruntime.InferenceSession(onnx_model.SerializeToString())
  1. 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

@hariharans29
Copy link
Member

Can you report this to the Keras converter project ? This seems like a conversion issue.

For the target conversion opset which 13, you can see here from the spec that neither Squeeze nor ReduceSum has an axes attribute (they are inputs).
https://github.com/onnx/onnx/blob/master/docs/Operators.md#Squeeze
https://github.com/onnx/onnx/blob/master/docs/Operators.md#ReduceSum

@hariharans29 hariharans29 added the converter related to ONNX converters label Apr 14, 2021
@chan4cc
Copy link
Author

chan4cc commented Apr 14, 2021

@hariharans29 OK, I will open a new issue in keras2onnx.
And I want to know, Is it caused by keras2onnx not converting op Squeeze/ReduceSum with an axes attribute in the onnx_model ?

@hariharans29
Copy link
Member

It is because keras2onnx is putting a Squeeze/ReduceSum node with axes attribute which is an invalid combination for opset-13. It needs to ensure that axes is an input for opset-13 (see the spec listed above)

@faxu
Copy link
Contributor

faxu commented Apr 19, 2021

Closing issue in this repo. @chan4cc you may also want to try the tensorflow-onnx converter for the keras model. It has a more active community and support team than the keras converter and should also work on Keras models.

@faxu faxu closed this as completed Apr 19, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
converter related to ONNX converters
Projects
None yet
Development

No branches or pull requests

3 participants