question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unsupported shape calculation for operator BatchNormalization

See original GitHub issue

I made a new model using keras, and saved it to an .hdf file using a callback during training.

I reloaded the model and tried to convert to an ONNX model:

model = keras.models.load_model(filename)
convert_model = winmltools.convert_keras(keras_model, 7)
winmltools.save_model(convert_model, onnx_model_name)

convert_keras throws an error here. Any idea what I might be doing wrong? python 3.6.2, Tensorflow 1.8, Keras 2.1.5, onnxmltools 1.3.2

The keras-retinanet implementation uses keras_resnet which has BatchNormalization referred to in the error.

Error below:

ValueError                                Traceback (most recent call last)
<ipython-input-11-800754ba9409> in <module>()
----> 1 convert_to_onnx(model, "snapshots/onnxmodel.onnx")

<ipython-input-9-d58ccba40905> in convert_to_onnx(keras_model, onnx_model_name)
      2 
      3         ########  Conver to ONNX ############
----> 4         convert_model = winmltools.convert_keras(keras_model, 7)
      5         winmltools.save_model(convert_model, onnx_model_name)

~/.local/lib/python3.6/site-packages/winmltools/convert/main.py in convert_keras(model, target_opset, name, initial_types, doc_string, default_batch_size, channel_first_inputs, custom_conversion_functions, custom_shape_calculators)
    151     return _convert_keras(model, name=name, target_opset=target_opset, initial_types=initial_types, doc_string=doc_string,
    152                           default_batch_size=default_batch_size, channel_first_inputs=channel_first_inputs,
--> 153                           custom_conversion_functions=custom_conversion_functions, custom_shape_calculators=custom_shape_calculators)
    154 
    155 

~/.local/lib/python3.6/site-packages/onnxmltools/convert/keras/convert.py in convert(model, name, default_batch_size, initial_types, doc_string, target_opset, targeted_onnx, channel_first_inputs, custom_conversion_functions, custom_shape_calculators)
     41                            custom_conversion_functions, custom_shape_calculators)
     42 
---> 43     topology.compile()
     44 
     45     if name is None:

~/.local/lib/python3.6/site-packages/onnxmltools/convert/common/_topology.py in compile(self)
    623         self._resolve_duplicates()
    624         self._fix_shapes()
--> 625         self._infer_all_types()
    626         self._check_structure()
    627 

~/.local/lib/python3.6/site-packages/onnxmltools/convert/common/_topology.py in _infer_all_types(self)
    499                 pass  # in Keras converter, the shape calculator can be optional.
    500             else:
--> 501                 operator.infer_types()
    502 
    503     def _resolve_duplicates(self):

~/.local/lib/python3.6/site-packages/onnxmltools/convert/common/_topology.py in infer_types(self)
    101     def infer_types(self):
    102         # Invoke a core inference function
--> 103         _registration.get_shape_calculator(self.type)(self)
    104 
    105 

~/.local/lib/python3.6/site-packages/onnxmltools/convert/common/_registration.py in get_shape_calculator(operator_name)
     66     '''
     67     if operator_name not in _shape_calculator_pool:
---> 68         raise ValueError('Unsupported shape calculation for operator %s' % operator_name)
     69     return _shape_calculator_pool[operator_name]

ValueError: Unsupported shape calculation for operator <class 'keras_resnet.layers._batch_normalization.BatchNormalization'>

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jiafatomcommented, Mar 22, 2019

The keras2onnx converter calls tf2onnx converter to process some layers. This error throws from tf2onnx and indicates that the graph has cycles (so it cannot handle). Does this graph contain cycles?

0reactions
hotamycommented, Dec 28, 2020

@scutzhe I have same problem.Is this problem solved?

Read more comments on GitHub >

github_iconTop Results From Across the Web

tf.layers.batch_normalization parameters - Stack Overflow
I assume that this parameter is used when calculating the "mean" value for a certain mini batch in the corresponding hidden layer. With...
Read more >
Python Runtime for ONNX operators
The dequantization formula is y = (x - x_zero_point) * x_scale. 'x_scale' and 'x_zero_point' must have same shape, and can be either a...
Read more >
tf.Tensor | TensorFlow v2.11.0
An error is raised if an incompatible shape is passed. ... Divides x / y elementwise (using Python 2 division operator semantics). (deprecated)....
Read more >
Operator Objects (Legacy) — NVIDIA DALI 1.20.0 ...
Corner coordinates are transformed according to the following formula: ... With these shapes, batch normalization is not possible, because the non-reduced ...
Read more >
Support for tensorflow ops for newer TF version - Development
I havent encountered any other non supported op. ... in from_tensorflow sym, params = g.from_tensorflow(graph, layout, shape, outputs) File ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found