No module named 'tensorflow.keras.layers.experimental.preprocessing'

23,893

Solution 1

You need update TensorFlow. You can try with

pip install tensorflow==2.0.0

or, if you use gpu version

pip install tensorflow-gpu==2.0.0 

If doesn't solve your issue, you can also try with 2.2.0 version.

For more details, in this issue follow this answer

Solution 2

you need to update the version of your TensorFlow. For me, 2.2.0 solved the problem. I also checked with the higher versions and worked ok.

pip install tensorflow==2.2.0

or

pip install tensorflow-gpu==2.2.0 
Share:
23,893
Imdadul Haque
Author by

Imdadul Haque

In the early of my life, studay abroad I mostly wanted and for that I am working to prepared myself. I am CSE student and working with Machine Learning and Reinforcement Learning I mostly like. I have already completed some Web project and also ML projects and working for research Papers publications. I already add some of my achievements in Developer Story. And I am Full Stack Software Developer using Laravel, ReactJS, JavaScript, Bootstrap, CSS, HTML. As a programmer my life moto is, //Life Moto if(sad()===true){ sad().stop(); beAwesome(); } Coursera Profile Link: Imdadul Haque

Updated on January 25, 2021

Comments

  • Imdadul Haque
    Imdadul Haque over 3 years

    Below the code

    import numpy as np
    np.random.seed(0)
    from sklearn import datasets
    import matplotlib.pyplot as plt
    %matplotlib inline
    %config InlineBackend.figure_format ='retina'
    
    from keras.models import Sequential
    from keras.layers import Dense
    from keras.optimizers import SGD
    

    below the Error message

    ---------------------------------------------------------------------------
    ModuleNotFoundError                       Traceback (most recent call last)
    ~\Anaconda3\lib\site-packages\keras\__init__.py in <module>
          2 try:
    ----> 3     from tensorflow.keras.layers.experimental.preprocessing import RandomRotation
          4 except ImportError:
    
    ModuleNotFoundError: No module named 'tensorflow.keras.layers.experimental.preprocessing'
    
    During handling of the above exception, another exception occurred:
    
    ImportError                               Traceback (most recent call last)
    <ipython-input-5-943507dd87a6> in <module>
          6 get_ipython().run_line_magic('config', "InlineBackend.figure_format ='retina'")
          7 
    ----> 8 from keras.models import Sequential
          9 from keras.layers import Dense
         10 from keras.optimizers import SGD
    
    ~\Anaconda3\lib\site-packages\keras\__init__.py in <module>
          4 except ImportError:
          5     raise ImportError(
    ----> 6         'Keras requires TensorFlow 2.2 or higher. '
          7         'Install TensorFlow via `pip install tensorflow`')
          8 
    
    ImportError: Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow
    

    Note:` I think, the main problem is Tensorflow version. I used somes command and that's are bellow,

    conda create -n tf tensorflow
    conda activate tf
    

    and I also used the below command

    conda create -n tf-gpu tensorflow-gpu
    conda activate tf-gpu
    

    But it don't works , Please help for solve the error.

  • Imdadul Haque
    Imdadul Haque over 3 years
    Ashraful Alom brother, still now it's show the same error
  • Guilherme Kich
    Guilherme Kich over 3 years
    Hey Imdadul, close and open Python editor/shell again, it worked here. For me I got the same error, I updated the tensorflow and the error was on still. Then I closed Python and opened again. it worked!