`ValueError: Keras layer '<class 'keras_resnet.layers._batch_normalization.BatchNormalization'>' not supported.` when trying to convert to coreml
See original GitHub issueI learned a model with keras-retinanet which seems to work pretty well, now I would like to convert it to a coreml model to use it in my iOS app:
import coremltools
coreml_model = coremltools.converters.keras.convert(model)
coreml_model.save('my_model.mlmodel')
Unfortunately I get the following error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-7-ba230c07a72c> in <module>()
1 import coremltools
----> 2 coreml_model = coremltools.converters.keras.convert(model)
3 # Saving the Core ML model to a file.
4 coreml_model.save('my_model.mlmodel')
/home/jonas/projects/keras/keras-env/local/lib/python2.7/site-packages/coremltools/converters/keras/_keras_converter.pyc in convert(model, input_names, output_names, image_input_names, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale, class_labels, predicted_feature_name, model_precision, predicted_probabilities_output, add_custom_layers, custom_conversion_functions)
743 predicted_probabilities_output,
744 add_custom_layers,
--> 745 custom_conversion_functions=custom_conversion_functions)
746
747 return _MLModel(spec)
/home/jonas/projects/keras/keras-env/local/lib/python2.7/site-packages/coremltools/converters/keras/_keras_converter.pyc in convertToSpec(model, input_names, output_names, image_input_names, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale, class_labels, predicted_feature_name, model_precision, predicted_probabilities_output, add_custom_layers, custom_conversion_functions, custom_objects)
541 add_custom_layers=add_custom_layers,
542 custom_conversion_functions=custom_conversion_functions,
--> 543 custom_objects=custom_objects)
544 else:
545 raise RuntimeError(
/home/jonas/projects/keras/keras-env/local/lib/python2.7/site-packages/coremltools/converters/keras/_keras2_converter.pyc in _convert(model, input_names, output_names, image_input_names, is_bgr, red_bias, green_bias, blue_bias, gray_bias, image_scale, class_labels, predicted_feature_name, predicted_probabilities_output, add_custom_layers, custom_conversion_functions, custom_objects)
185
186 # Check valid versions
--> 187 _check_unsupported_layers(model, add_custom_layers)
188
189 # Build network graph to represent Keras model
/home/jonas/projects/keras/keras-env/local/lib/python2.7/site-packages/coremltools/converters/keras/_keras2_converter.pyc in _check_unsupported_layers(model, add_custom_layers)
98 else:
99 if type(layer) not in _KERAS_LAYER_REGISTRY:
--> 100 raise ValueError("Keras layer '%s' not supported. " % str(type(layer)))
101 if isinstance(layer, _keras.layers.wrappers.TimeDistributed):
102 if type(layer.layer) not in _KERAS_LAYER_REGISTRY:
ValueError: Keras layer '<class 'keras_resnet.layers._batch_normalization.BatchNormalization'>' not supported.
I’m confused by that batchnormalization as i didn’t find that string anywhere in this repo…
Is there a way to convert it to coreml and/or use it in an Android app? I searched for tutorials but didn’t find any unfortunately.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
`ValueError: Keras layer '<class 'keras_resnet.layers ... - GitHub
ValueError: Keras layer '<class 'keras_resnet.layers._batch_normalization.BatchNormalization'>' not supported. when trying to convert to coreml #139.
Read more >tf.keras model to coreml model, BatchNormalization not ...
Yet, I got the error : ValueError: Keras layer '<class 'keras.layers.normalization_v2.BatchNormalization'>' not supported. when I ran :
Read more >Advanced Tips for Core ML - Heartbeat
Because Apple's coremltools library does not support keras-contrib, we'll end up with the following error when we try to convert our model: ValueError:...
Read more >Batch Normalization in practice: an example with Keras and ...
Batch normalization is a technique for training very deep neural networks that standardizes the inputs to a layer for each mini-batch.
Read more >Working with preprocessing layers | TensorFlow Core
With Keras preprocessing layers, you can build and export models that are truly end-to-end: models that accept raw images or raw structured data ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just want to add the following: I’ve looked into this before, you need to re-implement all custom layers used by keras_resnet and keras-retinenet in Swift for this to work, this is possible since the latest version of coreml but it will be a lot of work to port everything over. Also I have my doubts if the Retinanet architecture will fit on a mobile device.
I was not able to convert it or adapt it. But in case it helps, I ended up using MobileNet and tflite instead. This tutorial was quite helpful.
https://towardsdatascience.com/deeppicar-part-6-963334b2abe0