Skip to content
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

Cannot import name relu6 #6

Open
tensor-flower opened this issue Jun 13, 2018 · 10 comments
Open

Cannot import name relu6 #6

tensor-flower opened this issue Jun 13, 2018 · 10 comments

Comments

@tensor-flower
Copy link

Using TensorFlow backend.
Traceback (most recent call last):
  File "train.py", line 9, in <module>
    from mobilenet_v2 import MobileNetv2
  File "/home/wq/MobileNetV2/mobilenet_v2.py", line 13, in <module>
    from keras.applications.mobilenet import relu6, DepthwiseConv2D
ImportError: cannot import name relu6

There seems to be some name changes since you write the script.

@gaoshine
Copy link

gaoshine commented Jun 25, 2018

yes, if you use keras2.2 .
from keras.applications.mobilenet import relu6, DepthwiseConv2D .
i think in 2.2, it change something.

@EggyDream
Copy link

I think in keras mobilenet implement are moving place,
from keras.applications to keras_applications.

Personally I replace,
from keras.applications.mobilenet import relu6, DepthwiseConv2D
to,
from keras_applications.mobilenet import relu6
from keras.layers import DepthwiseConv2D

The reason I uese DepthswiseConv2D from layers
is I found that the mobilenet's DepthswiseConv2D is import from layers

Also It seems keras 2.2 has its own mobilenet-v2 implement.

@jmherrmann
Copy link

jmherrmann commented Jul 23, 2018

Had the same issue, this worked for me:

from keras import models
from keras_applications import mobilenet_v2

model = models.load_model(path_model_checkpoint, custom_objects={'relu6': mobilenet_v2.relu6})
model.summary()

Had the idea for the fix from here: keras-team/keras@468f080

@JustinAsdz
Copy link
Contributor

@jmherrmann Still not work

AttributeError: module 'keras_applications.mobilenet_v2' has no attribute 'relu6'

can you help me with it?

@jmherrmann
Copy link

Which Keras version are you on @BokaiLIAN?

@JustinAsdz
Copy link
Contributor

I have solved the problem by reinstall keras=2.1.4
Still thanks a lot @jmherrmann

@chxy95
Copy link

chxy95 commented Oct 17, 2018

In keras 2.2, you can open the mobilenet_v2.py file in the keras_applications folder to find how to use relu6 rightly. In fact, you only need replace the Activation('relu6')(x) of mobilenet_v2.layers.ReLU(6.)(x).

@xincxiong
Copy link

As I reinstall keras=2.1.5, the backend is set to theano, but I cannot change the backend! why???
keras=2.1.5 still cannot work!!

Anyone solved this issue?? How ??

@SteveIb
Copy link

SteveIb commented Oct 25, 2018

I have tried
with CustomObjectScope({'relu6': keras.layers.ReLU(6.),'DepthwiseConv2D': keras.layers.DepthwiseConv2D}):
model = load_model('****.hdf5')

but I got the following error:
ValueError: axes don't match array

my TF is 1.11 my keras is 2.2.4, python 2.7.
Im trying to convert the model on the same machine and environment i have trained on.
any suggestions?

@joseildofilho
Copy link

Why not use SeparableConv2D instead DepthConv2D and a relu with parameter max_value ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants