Mian Afra
Mian Afra

Reputation: 11

ImportError: cannot import name 'Layer' from 'keras.engine'

I am facing a difficulty in solving this error. I want to pass the Layer object to a class in python,I am facing an import error. Here is the error message.

Traceback (most recent call last):
  File "/Users/mianafra/Documents/NLP/D2V-BiGRU-CRF/annotate_docs.py", line 3, in <module>
    from wrap import Sequence
  File "/Users/mianafra/Documents/NLP/D2V-BiGRU-CRF/wrap.py", line 6, in <module>
    from models_d2v import BiLSTMCRFD2V_to_dense, save_model, load_model
  File "/Users/mianafra/Documents/NLP/D2V-BiGRU-CRF/models_d2v.py", line 10, in <module>
    from layers import CRF
  File "/Users/mianafra/Documents/NLP/D2V-BiGRU-CRF/layers.py", line 9, in <module>
    from keras.engine import Layer
ImportError: cannot import name 'Layer' from 'keras.engine'   

Upvotes: 1

Views: 5352

Answers (3)

QueueTi
QueueTi

Reputation: 11

Try importing

from tensorflow.keras.layers import Layer

instead of

from keras.layers import Layer

Upvotes: 0

Eyal Elbaz
Eyal Elbaz

Reputation: 51

I think there is something wrong with your tensorflow installation, have you tried to reinstall tensorflow? maybe try look here: https://github.com/tensorflow/tensorflow/issues/24847.

Try install keras without tf package using:

pip3 install keras

Upvotes: 0

AKX
AKX

Reputation: 168903

Make sure you have installed the correct Keras version required by the project.

If it's this D2V-BiGRU-CRF project, it seems to be

keras==2.2.0

Upvotes: 1

Related Questions