Unsupported shape calculation for operator Dropout
See original GitHub issueI 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:
- Created 5 years ago
- Comments:13 (8 by maintainers)
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:
@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 dopip install -I git+https://github.com/onnx/onnxmltools
. Releasing may take a while. Thanks.