2

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.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Julie Parker
  • 21
  • 1
  • 4

2 Answers2

0

It seems your python is python 3.9. Make sure your python version is Python 3.5–3.8. check your version by $ python3 --version.

Reinstall python 3.8 as tensorflow does not support for a higher version of python. Use the command line to install. conda install python=3.8.

Darshan
  • 71
  • 11
  • I have Python 3.8.5 – Julie Parker Nov 27 '20 at 18:13
  • Then other packages might have a conflict with TensorFlow. Try the following: make a separate temporary conda environment, install python=3.8, and install TensorFlow and check whether it works. I did the same and it works. – Darshan Nov 27 '20 at 18:18
  • I just did that - installed python and tensorflow from anaconda (and only those two). Now I have some of the layers, but not all. I still can't run from tensorflow.keras.layers.experimental.preprocessing import StringLookup. But I can run from tensorflow.keras.layers.experimental.preprocessing import StringLookup – Julie Parker Nov 27 '20 at 18:36
  • I think there is a typo in your last comment. – Darshan Nov 27 '20 at 18:41
  • My apologies, I still can't run from tensorflow.keras.layers.experimental.preprocessing import StringLookup. I can run from tensorflow.keras.layers.experimental.preprocessing import RandomFlip – Julie Parker Nov 27 '20 at 18:44
  • which python IDE you are using? could you try it directly in the terminal? – Darshan Nov 27 '20 at 18:48
  • That's what I did with the new environment. I created the new environment with python=3.8.0, then installed tensorflow with conda install -c anaconda tensorflow. Then used python directly in the terminal to attempt several imports. – Julie Parker Nov 27 '20 at 19:01
  • Bingo ! Install TensorFlow with following : `pip install tensorflow` – Darshan Nov 27 '20 at 19:28
  • ran into AVX issues with Tensorflow. So did the install from source and compiled my own whl for tensorflow. Now it works! :-) Thanks! – Julie Parker Nov 29 '20 at 00:11
0

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

desertnaut
  • 57,590
  • 26
  • 140
  • 166