Search code examples
tensorflowkerasimporterrorkeras-layer

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.


Solution

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