-
Notifications
You must be signed in to change notification settings - Fork 626
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
Keras mobilenet can't be imported (missing Relu6 / DepthwiseConv2D) #38
Comments
Actually the only missing portion is the ReLU6, the DepthwiseConv2D is already there. |
PR#44 is up, should fix this issue. |
PR #44 has been merged. Closing this issue. |
So I just ran into something similar:
And I just built from source. @luke14free did you have to do anything else to convert your model? |
Can you provide (1) trace stack for this error and (2) the Keras version you're using? |
@seantempesta are you doing this?
|
Full stack trace below. I was loading just the keras .h5 file.
|
I ended up completing the conversion by just converting the model after building it in Keras and loading the weights. I can't post the entire file, but here's the gist: ##############################################################
############ LET'S DEFINE OUR MODEL #################
###############################################################
modelBase = applications.MobileNet(weights='imagenet',include_top=False, input_shape = (img_width, img_height, 3))
...
model.load_weights('mobilenet-weights.h5')
import coremltools
coreml_model = coremltools.converters.keras.convert(model) |
Hi @seantempesta does not seems to work for me. Please provide more sample if possible |
This seems to fix the issue for me keras-team/keras#7431 (comment) |
@seantempesta You are probably using coremltools from pip. |
@tatsuya-ogawa: No, I built it from source. Granted that was 19 days ago, so I don't know if you've merged a fix recently? |
If your keras is at "from tensorflow.python import keras" instead of at "import keras" then here is what worked for me:
|
with tensorflow 1.9 and keras 2.2.0 this is what I did and it worked completely: for complete model you should import your model separately, e.g. using model_from_json |
I have tried but I got the following error: my TF is 1.11 my keras is 2.2.4, python 2.7. |
I suggest for conversion use Keras 2.1.6 to import relu6- import relu6 from "keras.applications.mobilenet". the rest is just as I explained above. (tensorflow version does not matter) |
Hi, i downgraded keras to 2.1.6 My code: import keras from keras.models import model_from_json with open('model.json','r') as f: from tensorflow.python.keras.models import load_model Im getting the following error: ValueError: Unknown layer: ReLU |
You should train it again, with this version
…On Oct 28, 2018 10:02 AM, "SteveIb" ***@***.***> wrote:
I suggest for conversion use Keras 2.1.6 to import relu6- import relu6
from "keras.applications.mobilenet". the rest is just as I explained
above. (tensorflow version does not matter)
Hi, i downgraded keras to 2.1.6
My code:
import keras
from keras.models import model_from_json
with open('model.json','r') as f:
json = f.read()
loaded_model = model_from_json(json)
from tensorflow.python.keras.models import load_model
from keras.applications.mobilenet import MobileNet
from tensorflow.python.keras.applications import mobilenet
from tensorflow.python.keras.utils.generic_utils import CustomObjectScope
with CustomObjectScope({'relu6': keras.applications.mobilenet.relu6,'DepthwiseConv2D':
keras.applications.mobilenet.DepthwiseConv2D}):
loaded_model.load_weights('**********.hdf5')
Im getting the following error:
ValueError: Unknown layer: ReLU
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#38 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADmxxrE7eeFO5AtZZZeCvZPnRmx3HzC1ks5upWSlgaJpZM4Pxqxu>
.
|
I trained again. ValueError: Unknown activation function:relu6 |
I'm using this library to train on MobileNet |
Had this same issue: my fix:
|
Am facing the issue still from tensorflow.python.keras.models import load_model with CustomObjectScope({'relu6': mobilenet.relu6,'DepthwiseConv2D': mobilenet.DepthwiseConv2D}):transfer_model = load_model('modeltransfer1.h5') AttributeError: module 'tensorflow.python.keras.applications.mobilenet' has no attribute 'relu6' Please help on this |
what worked for me is loading the weights and json individually. Recreate the Keras model object from the json data
|
Unify attention modules
I have a custom trained MobileNet network from Keras and I bump into an issue about CoreML Tools not recognizing Relu6 as an activation function.
my keras model is something like:
And after training I try to convert it with:
But this raises:
RuntimeError: Unsupported option activation=relu6 in layer Dense(conv1_relu)
Because coreML Tools doesn't know what DepthwiseConv2D and Relu6 are.
The text was updated successfully, but these errors were encountered: