'tensorflow.keras.layers.experimental.preprocessing'이라는 모듈이 없습니다.

Aug 22 2020

코드 아래

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

오류 메시지 아래

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

참고 :` 주된 문제는 Tensorflow 버전이라고 생각합니다. 나는 somes 명령을 사용했고 그것은 다음과 같습니다.

conda create -n tf tensorflow
conda activate tf

그리고 나는 또한 아래 명령을 사용했습니다

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

그러나 작동하지 않습니다. 오류를 해결하도록 도와주세요.

답변

3 ashraful16 Aug 23 2020 at 02:45

TensorFlow를 업데이트해야합니다. 시도 할 수 있습니다.

pip install tensorflow==2.0.0

또는 gpu 버전을 사용하는 경우

pip install tensorflow-gpu==2.0.0 

자세한 내용은 이번 호에서 다음 답변을 따르십시오.

2 AliPrf Oct 14 2020 at 22:17

TensorFlow의 버전을 업데이트해야합니다. 나를 위해 2.2.0이 문제를 해결했습니다. 나는 또한 더 높은 버전으로 확인하고 정상적으로 작동했습니다.

pip install tensorflow==2.2.0

또는

pip install tensorflow-gpu==2.2.0