New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ValueError: Unknown layer: ReLU Converting a MobileNet pre-trained model #267
Comments
This doesn't seem like a converter error. To debug, for the moment, first just try to load the Keras model and see if that works without errors:
|
Thank you for you reply. I changed it to keras 2.2.2 and he model loaded successfully. But I got this |
Ok I fixed this but now I am getting this error: Traceback (most recent call last): |
@aminecherif94 I was having a similar issue, try this: from keras.utils.generic_utils import CustomObjectScope
with CustomObjectScope({'relu6': keras.applications.mobilenet.relu6, 'DepthwiseConv2D': keras.applications.mobilenet.DepthwiseConv2D}):
# coreml conversion code |
I've got the same error. Coremltools needs an upgrade. |
Yeah, I had to rewrote some of the script to make it work. DepthwiseConv2D and RELU6 have to be added. Also, lambda layers are not handled by CoreML. |
You should be able to use the tip of master. |
Thanks, @aseemw. I installed from the GitHub repo instead of pip repository: However, I have other issues from |
@mmalekzadeh Please write down the full error message. |
@aminecherif94 Here's the error:
|
It seems like there is a problem with you Keras model as CoreML is not able to get the successor or next layers of your Keras model. Please do this to visualize the layers of your model and copy paste the output here so that I can see what is the problem with your model : print(mymodel.summary()) |
Thanks, @aminecherif94. But I don't think so,
|
Python raises a KeyError whenever a dict() object is requested (using the format a = adict[key]) and the key is not in the dictionary. In your case, KeyError: 'Decoder', which means it is not able to get the successor of layer 'Decoder'. But Decoder layer logically can't have a successor as it is the final layer. So the problem is with the output layer. To test what I am saying just import any pertained Keras model and convert it to test if CoreML can convert it. But If I had to take a wild guess, when you implemented the Decoder layer, you did not specify it as being the output layer. Like this: outputs = Conv2D(...)(base_model.output) |
Here is the code where you are getting the error:
It calls the function |
But |
That is what I am saying, when you implemented the last layer |
Thanks, @aminecherif94, for the hints. I've added a |
It was my pleasure @mmalekzadeh :) |
For Keras 2.2.4 and Tensorflow 1.12.0 I found a solution. Save model weights & architecture like:
And for converting a model to CoreML .mlmodel I use:
|
It sounds like the original issue has been solved. So I'm going to close this issue. If there are additional problems that need attention, please create new issues. |
I am converting a MobileNet pre-trained model that I trained using Keras. I am getting this error with Keras 2.1.6
Traceback (most recent call last):
File "keras_to_coreml_converter.py", line 18, in
class_labels=output_labels, image_input_names='image')
File "/home/francoiszerhouni/anaconda3/lib/python3.6/site-packages/coremltools/converters/keras/_keras_converter.py", line 752, in convert
custom_conversion_functions=custom_conversion_functions)
File "/home/francoiszerhouni/anaconda3/lib/python3.6/site-packages/coremltools/converters/keras/_keras_converter.py", line 550, in convertToSpec
custom_objects=custom_objects)
File "/home/francoiszerhouni/anaconda3/lib/python3.6/site-packages/coremltools/converters/keras/_keras2_converter.py", line 192, in _convert
model = _keras.models.load_model(model, custom_objects = custom_objects)
File "/home/francoiszerhouni/anaconda3/lib/python3.6/site-packages/keras/models.py", line 270, in load_model
model = model_from_config(model_config, custom_objects=custom_objects)
File "/home/francoiszerhouni/anaconda3/lib/python3.6/site-packages/keras/models.py", line 347, in model_from_config
return layer_module.deserialize(config, custom_objects=custom_objects)
File "/home/francoiszerhouni/anaconda3/lib/python3.6/site-packages/keras/layers/init.py", line 55, in deserialize
printable_module_name='layer')
File "/home/francoiszerhouni/anaconda3/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 144, in deserialize_keras_object
list(custom_objects.items())))
File "/home/francoiszerhouni/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 2525, in from_config
process_layer(layer_data)
File "/home/francoiszerhouni/anaconda3/lib/python3.6/site-packages/keras/engine/topology.py", line 2511, in process_layer
custom_objects=custom_objects)
File "/home/francoiszerhouni/anaconda3/lib/python3.6/site-packages/keras/layers/init.py", line 55, in deserialize
printable_module_name='layer')
File "/home/francoiszerhouni/anaconda3/lib/python3.6/site-packages/keras/utils/generic_utils.py", line 138, in deserialize_keras_object
': ' + class_name)
ValueError: Unknown layer: ReLU
The text was updated successfully, but these errors were encountered: