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 Dropout

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)
winml_onnx_model = onnxmltools.convert_keras(model)

convert_keras throws an error here. Any idea what I might be doing wrong? I’m on Windows 10, python 3.6.2, Tensorflow 1.8, Keras 2.1.5, onnxmltools 1.2.0.0116, winmltools 1.2.0.0725

The model uses the following operators (but the error seems to be due to the Dropout layer):

Activation, Dropout, BatchNormalization, Convolution2D, MaxPooling2D, GlobalAveragePooling2D

If I do model.summary() everything seems fine with my model. Batch size is always specified as “None” in the model summary, so I wonder if there’s some issue with how to deal with batch size in the ONNx conversion (this is my first time making an ONNX model)

Thanks!

UPDATE: This simple model gives the same error. I also tried specifying the batch_input_shape explicitly to just allow 1 item in the batch, and it didn’t change anything:

model2 = Sequential()
model2.add(Dense(50, batch_input_shape=[1, 5]))
model2.add(Dropout(0.5))
winml_onnx_model2 = onnxmltools.convert_keras(model2)

Error below:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-15-da007af6c51d> in <module>()
----> 1 winml_onnx_model = onnxmltools.convert_keras(model)

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\onnxmltools\convert\main.py in convert_keras(model, name, initial_types, doc_string, targeted_onnx, custom_conversion_functions, custom_shape_calculators)
     36     from .keras.convert import convert
     37     return convert(model, name, initial_types,
---> 38                    doc_string, targeted_onnx, custom_conversion_functions, custom_shape_calculators)

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\onnxmltools\convert\keras\convert.py in convert(model, name, initial_types, doc_string, targeted_onnx, custom_conversion_functions, custom_shape_calculators)
     40     topology = parse_keras(model, initial_types, targeted_onnx, custom_conversion_functions, custom_shape_calculators)
     41 
---> 42     topology.compile()
     43 
     44     if name is None:

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\onnxmltools\convert\common\_topology.py in compile(self)
    607         self._resolve_duplicates()
    608         self._fix_shapes()
--> 609         self._infer_all_types()
    610         self._check_structure()
    611 

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\onnxmltools\convert\common\_topology.py in _infer_all_types(self)
    493                 pass  # in Keras converter, the shape calculator can be optional.
    494             else:
--> 495                 operator.infer_types()
    496 
    497     def _resolve_duplicates(self):

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\onnxmltools\convert\common\_topology.py in infer_types(self)
     95     def infer_types(self):
     96         # Invoke a core inference function
---> 97         _registration.get_shape_calculator(self.type)(self)
     98 
     99 

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\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.layers.core.Dropout'>

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
eraoulcommented, Aug 15, 2018

Thanks so much Wei-Sheng and Wenbing – the converter works for me now. Really appreciate the quick fix!

On Tue, Aug 7, 2018 at 4:17 PM, Wei-Sheng Chin notifications@github.com wrote:

Hi @eraoul https://github.com/eraoul, @wenbingl https://github.com/wenbingl just merge a fix for supporting Dropout. Would you mind to try it again? Thanks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/onnx/onnxmltools/issues/124#issuecomment-411232677, or mute the thread https://github.com/notifications/unsubscribe-auth/ABBIPkjwHlontmiFnEZzdEkPqBNapkY_ks5uOh_zgaJpZM4Vrc7v .

1reaction
wschincommented, Aug 3, 2018

@eraoul , you can build from source via pip install git+https://github.com/onnx/onnxmltools once the code is merged. If you have already installed Onnxmltools and want to overwrite it you can do pip install -I git+https://github.com/onnx/onnxmltools. Releasing may take a while. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

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 >
Supported scikit-learn Models - ONNX
Name Package Supported ARDRegression linear_model Yes AdaBoostClassifier ensemble Yes AdaBoostRegressor ensemble Yes
Read more >
Import pretrained ONNX network as a function - MathWorks
Specify the file to import as shufflenet with operator set 9 from the ONNX ... Calculate the class probabilities by specifying the image...
Read more >
Available TensorFlow Ops | Cloud TPU
This page lists the TensorFlow Python APIs and graph operators available on ... tf.random_normal, shape must be a compile-time constant. ... tf.nn.dropout.
Read more >
How to Convert a PyTorch Model to ONNX in 5 Minutes - Deci AI
This means that if you have an operator that is in the “unsupported operators” section, you will not be able to export that...
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