MobileNetV2
MobileNetV2 copied to clipboard
Cannot import name relu6
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.
yes, if you use keras2.2 .
from keras.applications.mobilenet import relu6, DepthwiseConv2D .
i think in 2.2, it change something.
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.
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 Still not work
AttributeError: module 'keras_applications.mobilenet_v2' has no attribute 'relu6'
can you help me with it?
Which Keras version are you on @BokaiLIAN?
I have solved the problem by reinstall keras=2.1.4 Still thanks a lot @jmherrmann
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).
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 ??
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?
Why not use SeparableConv2D instead DepthConv2D and a relu with parameter max_value ?