Search code examples
pythontensorflowkeras

Error: cannot import name 'StringLookup' from 'tensorflow.keras.layers.experimental.preprocessing'


I can import preprocessing:

from tensorflow.keras.layers.experimental import preprocessing

But I can't import or use any of the layers inside it:

from tensorflow.keras.layers.experimental.preprocessing import StringLookup

ImportError  Traceback (most recent call last)
<ipython-input-78-4f042fcbcc66> in <module>
----> 1 from tensorflow.keras.layers.experimental.preprocessing import StringLookup

ImportError: cannot import name 'StringLookup' from 'tensorflow.keras.layers.experimental.preprocessing' (/home/julie/miniconda3/envs/tf-gpu/lib/python3.8/site-packages/tensorflow/keras/layers/experimental/preprocessing/__init__.py)

I found several resources citing versions as the issue. My environment is running:

  • Tensorflow 2.2.0
  • Keras 2.4.3

Both were installed through conda.


Solution

  • The only solution that worked for me is:

    pip install tensorflow==2.6.0
    pip install keras==2.6.0
    

    By bringing both tf and keras to 2.6.0