MobileNetV2 icon indicating copy to clipboard operation
MobileNetV2 copied to clipboard

Cannot import name relu6

Open tensor-flower opened this issue 6 years ago • 10 comments

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.

tensor-flower avatar Jun 13 '18 11:06 tensor-flower

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

gaoshine avatar Jun 25 '18 14:06 gaoshine

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.

EggyDream avatar Jul 20 '18 04:07 EggyDream

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: https://github.com/keras-team/keras/commit/468f080c98f06780c950e5a78c9eeeaf9fff002e

jmherrmann avatar Jul 23 '18 07:07 jmherrmann

@jmherrmann Still not work

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

can you help me with it?

JustinAsdz avatar Aug 16 '18 02:08 JustinAsdz

Which Keras version are you on @BokaiLIAN?

jmherrmann avatar Aug 20 '18 06:08 jmherrmann

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

JustinAsdz avatar Aug 20 '18 06:08 JustinAsdz

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).

chxy95 avatar Oct 17 '18 08:10 chxy95

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 ??

xincxiong avatar Oct 20 '18 14:10 xincxiong

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?

SteveIb avatar Oct 25 '18 12:10 SteveIb

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

joseildofilho avatar Jan 01 '19 19:01 joseildofilho