Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tensorflow.keras can't import Activation

just installed tensorflow-gpu via:

conda install --yes tensorflow-gpu==1.12.0

Now when I run from tensorflow.keras import layers into the error:

ImportError: cannot import name 'Activation'

I tried removing tf and keras then reinstalling tf, but hasn't helped.

like image 577
Austin Avatar asked Oct 13 '25 05:10

Austin


2 Answers

This is due to a change in 1.12.0

As seen below; in 1.11, tensorflow uses tensorflow.python.keras.activations https://github.com/tensorflow/tensorflow/blob/r1.11/tensorflow/python/keras/layers/advanced_activations.py

However in 1.12, it doesn't exist anymore; https://github.com/tensorflow/tensorflow/blob/r1.12/tensorflow/python/keras/layers/advanced_activations.py

So, I think you can directly call the activation function as; keras.layers.{activation_function} e.g. keras.layers.LeakyReLU

Alternatively, you can downgrade.

like image 143
mokarakaya Avatar answered Oct 14 '25 23:10

mokarakaya


As @Amir replied, use tensorflow.python.keras. That worked for me!

like image 29
Monkshow Avatar answered Oct 14 '25 22:10

Monkshow