Deeplearning4j: Keras MobileNet import is not functioning

Created on 15 Aug 2018  路  12Comments  路  Source: eclipse/deeplearning4j

As already pictured in this issue, I am having some trouble getting to run the MobileNet model using Keras' model import.

While I can import and run any other Keras model without any problems, it does not work for the MobileNet model provided in dl4j-test-resources as it throws a DL4JInvalidInputException.
Thus, I suspect the problem to lie within the model.

I have created a Maven example you may pull here: https://github.com/TobiasGoerke/MobileNetKerasImportTest

Thanks!

Bug DL4J Keras

Most helpful comment

Same issue on my side as well. I am facing with either "Unsupported keras layer type Model" error or "Unsupported keras layer type ReLU" error while trying to import pretrained MobileNetV2 model. I think the reason of that is Keras' encoding type of pre-trained(application) models in config json. Keras directly adds a layer as "Model" to cover all mobilenet architecture like a container. But at the same time when we try to flatten this pre-trained model, DL4J throws "Unsupported keras layer type ReLU" exception this time. Thus we cant go further either ways. I guess this structure should be supported by DL4J in some way. Otherwise, we cant import really meaningful Keras models. Thanks...

All 12 comments

great. I'll pick it up tomorrow. thanks

Alright, thanks a lot for your support

@TobiasGoerke thanks again, fixed now

I am sorry for bringing this up again but this commit has not fixed the issue.
As I commented in the source code of the sample, the "alternative.hdf5" is a random model I found in another issue submittal. Although its author stated it to be an instance of MobileNet, it does not work as it is supposed to - any input results in the exact same output!
Therefore, you just replaced one broken model with another broken model.

In order to fix this problem, I exported the Python Keras models myself and updated my GitHub project.
This is the Python code I used:

from keras.applications import MobileNet
from keras.applications import MobileNetV2

MobileNet().save('mobileNet.h5')
MobileNetV2().save('mobileNetV2.h5')

Now, I wish I could just give you the working models and we'd be done with this.
Unfortunately, they do not work with DL4J, too. Following exception gets thrown:

UnsupportedKerasConfigurationException: Unsupported keras layer type ReLU. Please file an issue at http://github.com/deeplearning4j/deeplearning4j/issues.

I've seen that ReLU support is already available, so I don't know more about the origin of this exception. Please see the previously posted GitHub project for an updated sample. I will gladly provide you with more information in case you need them.
Thanks!

@TobiasGoerke sorry, I have completely misunderstood you. "ReLU" is indeed not a standard Keras layer type. You either have explicit activations within the layer or an "Activation" layer. I'll look more into this at a later point....

As the original paper specifies ReLU as a component does that mean pre-trained models cannot be imported?
Anyways, I am looking forward to your findings :+1:

Same issue on my side as well. I am facing with either "Unsupported keras layer type Model" error or "Unsupported keras layer type ReLU" error while trying to import pretrained MobileNetV2 model. I think the reason of that is Keras' encoding type of pre-trained(application) models in config json. Keras directly adds a layer as "Model" to cover all mobilenet architecture like a container. But at the same time when we try to flatten this pre-trained model, DL4J throws "Unsupported keras layer type ReLU" exception this time. Thus we cant go further either ways. I guess this structure should be supported by DL4J in some way. Otherwise, we cant import really meaningful Keras models. Thanks...

I am encountering the same issue when importing a pre-trained Keras mobile net.
Want to know when this issue can be fixed?

I am encountering the same issue when importing a pre-trained Keras mobile net.
Want to know when this issue can be fixed?

This problem is caused by keras updating (I guess). You can change the class name of "ReLU" into "Activation", which dl4j has supported. Here is the example code you can reference:
https://github.com/alessandrocapotondi/mobilenet_v1_stmcube_ai/blob/master/keras_model/keras_mobilenet_stm_cubemx_ai.ipynb

This is still an issue with dl4j 1.0.0-beta6 ... any chance this will be addressed ?

This one got missed/forgotten sorry, it shouldn't be too hard to add.

Thanks for reporting this.
It has been fixed here, and will be merged back to eclipse/deeplearning4j shortly. The fix will be available on snapshots within a few days.
https://github.com/KonduitAI/deeplearning4j/pull/143/
https://deeplearning4j.org/docs/latest/deeplearning4j-config-snapshots

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hanbaoan123 picture hanbaoan123  路  4Comments

AlexDBlack picture AlexDBlack  路  5Comments

sshepel picture sshepel  路  4Comments

turambar picture turambar  路  3Comments

novog picture novog  路  4Comments