Nessun modulo denominato "tensorflow.keras.layers.experimental.preprocessing"

Aug 22 2020

Di seguito il codice

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

sotto il messaggio di errore

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

Nota: ` Penso che il problema principale sia la versione di Tensorflow. Ho usato qualche comando e questo è sotto

conda create -n tf tensorflow
conda activate tf

e ho anche usato il comando seguente

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

Ma non funziona, per favore aiutaci a risolvere l'errore.

Risposte

3 ashraful16 Aug 23 2020 at 02:45

È necessario aggiornare TensorFlow. Puoi provare con

pip install tensorflow==2.0.0

oppure, se usi la versione gpu

pip install tensorflow-gpu==2.0.0 

Per maggiori dettagli, in questo numero segui questa risposta

2 AliPrf Oct 14 2020 at 22:17

è necessario aggiornare la versione di TensorFlow. Per me, 2.2.0 ha risolto il problema. Ho anche controllato con le versioni superiori e ho funzionato bene.

pip install tensorflow==2.2.0

o

pip install tensorflow-gpu==2.2.0