Keras: get two errors: cannot import activity_l2, cannot import layer_from_config

Created on 19 Mar 2017  Â·  23Comments  Â·  Source: keras-team/keras

Hi, I installed the latest keras(version 2.0.1) in docker. but the job failed when I try to import these two:

ImportError                               Traceback (most recent call last)
<ipython-input-6-72e860176cbd> in <module>()
     40 from keras.layers import TimeDistributed, Activation, SimpleRNN, GRU
     41 from keras.layers.core import Flatten, Dense, Dropout, Lambda
---> 42 from keras.regularizers import l2, activity_l2, l1, activity_l1
     43 from keras.layers.normalization import BatchNormalization
     44 from keras.optimizers import SGD, RMSprop, Adam

ImportError: cannot import name activity_l2



ImportError                               Traceback (most recent call last)
<ipython-input-7-a9899ee596df> in <module>()
     43 from keras.layers.normalization import BatchNormalization
     44 from keras.optimizers import SGD, RMSprop, Adam
---> 45 from keras.utils.layer_utils import layer_from_config
     46 from keras.metrics import categorical_crossentropy, categorical_accuracy
     47 from keras.layers.convolutional import *

ImportError: cannot import name layer_from_config

Most helpful comment

After change the import command, the code pass the compile.

#from keras.utils.layer_utils import layer_from_config
from keras.layers import deserialize as layer_from_config

Reference(http://forums.fast.ai/t/keras-2-released/1956)

All 23 comments

I experienced the same issue. But when installing keras==1.2.2, issue fixed.
I guess there're some breaking issues in 2.0.1

I have the same issue with 2.0.2

40 from keras.layers import TimeDistributed, Activation, SimpleRNN, GRU
41 from keras.layers.core import Flatten, Dense, Dropout, Lambda
42 from keras.regularizers import l2, activity_l2, l1, activity_l1
43 from keras.layers.normalization import BatchNormalization
44 from keras.optimizers import SGD, RMSprop, Adam

ImportError: cannot import name 'activity_l2'

I also have the same errors on keras 2.0.2. Anybody found any solutions?

You can find here https://github.com/fchollet/keras/commit/1c630c3e3c8969b40a47d07b9f2edda50ec69720 that activity_l2 is deleted and was equal to l2.

Try

pip install keras=1.2.2

On Sat, Mar 25, 2017 at 09:52 Gump.Cheng notifications@github.com wrote:

@WeiFoo https://github.com/WeiFoo Can I ask for the method to install
the keras1.22?

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/fchollet/keras/issues/5870#issuecomment-289212939,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGtrYfLyTdEwbSSWULjgYm-lv2zBHSGIks5rpRwUgaJpZM4MhpKo
.

>

+1-919-534-5251 <(919)%20534-5251>
http://fuwei.us
PhD Student in Computer Science,
North Carolina State University.

same issue

I have the same issue with Keras 2.0.2

Had the same issue with Keras 2.0.2. Downgrading to 1.2.2 helped.

same issue

I just ran into the same problem.
Windows 7, Jupyter notebook and Python 2.7.

Also run into this problem. Windows 10, Anaconda, Jupyter Notebook, Python 2.7 (installed with pip install keras)

Same here on 3.5.3 on Linux with keras 2.0.3. Is there a replacement function one can use to get the same functionality?

Instead of activity_l2you can use l2: https://github.com/fchollet/keras/commit/1c630c3e3c8969b40a47d07b9f2edda50ec69720#diff-6e3349d3f432641cc969b702bcd3edafL111

I am not familiar with layer_from_config, but it seams that it is replaced with layers.deserialize https://github.com/fchollet/keras/commit/ebe84eb3a1c3beb44e25fa4f00a89f2c71dde2cc#diff-98d8790a4331685d2a81334c398c4b58R229
from ..layers import deserialize as deserialize_layer

After change the import command, the code pass the compile.

#from keras.utils.layer_utils import layer_from_config
from keras.layers import deserialize as layer_from_config

Reference(http://forums.fast.ai/t/keras-2-released/1956)

I changed the code to this to make it work:

from keras.regularizers import L1L2, l2, l1
activity_l1 = L1L2(l1=1)
activity_l2 = L1L2(l2=1)

I was using a code from fast ai (utills.py) and ran into several issues related to keras version. Downgrading was a simple fix. ( pip install keras == 1.2.2 )

I had the exact same issue.
I tried downgrading Keras to 1.2.2. I was using the utils file from fast.ai. This is what i did and that worked to remove the error from activity_l2 but i still get the layer_from_config error

from keras.regularizers import L1L2, l2, l1
activity_l1 = L1L2(l1=1)
activity_l2 = L1L2(l2=1)

That solved the activity_l1 but the error for layer_from_config shill persists

Fast.ai student here. I found out that after you install Keras 1.2.2. you must restart Jupyter server.

None of the above worked for me. Downgraded to 1.2.2, restarted and ended up with the same error. Resorted to downloading updated modules here - https://github.com/roebius/deeplearning_keras2 and still hitting bugs. Hope this gets addressed soon.

I'm using python 2.7. pip install 'keras<2' + kernel restart resolved the issue for me.

I've just grep'd the entirety of deeplearning1 and there is no reference to the imported module. Consequently I suspect that "from keras import layer_from_config" can safely be commented out.

Closing as this is resolved

pip install keras==1.2.2
can solve the problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oweingrod picture oweingrod  Â·  3Comments

snakeztc picture snakeztc  Â·  3Comments

KeironO picture KeironO  Â·  3Comments

amityaffliction picture amityaffliction  Â·  3Comments

fredtcaroli picture fredtcaroli  Â·  3Comments