keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.31k stars 19.39k forks source link

get two errors: cannot import activity_l2, cannot import layer_from_config #5870

Closed songhuiming closed 5 years ago

songhuiming commented 7 years ago

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
WeiFoo commented 7 years ago

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

GTouzin commented 7 years ago

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'

nafizh commented 7 years ago

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

mike-grayhat commented 7 years ago

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

WeiFoo commented 7 years ago

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.

mayman99 commented 7 years ago

same issue

armando-fandango commented 7 years ago

I have the same issue with Keras 2.0.2

stiebels commented 7 years ago

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

lotempeledGong commented 7 years ago

same issue

Moondra commented 7 years ago

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

pierrewessman commented 7 years ago

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

darthdeus commented 7 years ago

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?

Danielhiversen commented 7 years ago

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

Opdoop commented 7 years ago

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)

riteshshrv commented 6 years ago

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)
Armarshall05 commented 6 years ago

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 )

Manish-rai21bit commented 6 years ago

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

SuperShinyEyes commented 6 years ago

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

liambarnett commented 6 years ago

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.

ranjita-naik commented 6 years ago

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

mattburrows commented 6 years ago

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.

wt-huang commented 5 years ago

Closing as this is resolved

Yan-echo commented 5 years ago

pip install keras==1.2.2 can solve the problem.