项目场景:
在尝试搭建深度学习环境的时候遭遇这个问题。 M1芯片的MacBookPro环境问题描述:
在搭建好了anaconda环境并且已经安装好了tensorflow,在pycharm运行程序的时候出现了这个问题。
错误展示:
/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:517: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:518: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:519: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:520: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:525: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
Traceback (most recent call last):
File "/Users/lizhihan/Downloads/毕业设计/Deep-Reinforcement-Learning-for-5G-Networks-master/test_environment/test_gpu_or_cpu.py", line 2, in <module>
from tensorflow.python.client import device_lib
File "/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/__init__.py", line 34, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/__init__.py", line 83, in <module>
from tensorflow.python import keras
File "/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/keras/__init__.py", line 26, in <module>
from tensorflow.python.keras import activations
File "/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/keras/activations.py", line 24, in <module>
from tensorflow.python.keras.utils.generic_utils import deserialize_keras_object
File "/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/keras/utils/__init__.py", line 39, in <module>
from tensorflow.python.keras.utils.multi_gpu_utils import multi_gpu_model
File "/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/keras/utils/multi_gpu_utils.py", line 22, in <module>
from tensorflow.python.keras.engine.training import Model
File "/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 40, in <module>
from tensorflow.python.keras.engine import network
File "/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/keras/engine/network.py", line 39, in <module>
from tensorflow.python.keras import saving
File "/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/keras/saving/__init__.py", line 33, in <module>
from tensorflow.python.keras.saving.saved_model import export_saved_model
ImportError: cannot import name 'export_saved_model' from 'tensorflow.python.keras.saving.saved_model' (/Users/lizhihan/coding/anaconda3/envs/tensorflow/lib/python3.7/site-packages/tensorflow/python/keras/saving/saved_model/__init__.py)
原因分析:
因为我是使用了keras库的,但是我的keras库是通过pycharm直接安装的最新版,除此之外我在这个anaconda环境中使用的python版本是3.7,所以出现了版本不兼容的问题。对应下面的版本,进行重新配置环境,就可以解决了。
解决方案:
对应下面的版本,进行重新配置环境,就可以解决了。
举例来说,我要配置1.14版本的tensorflow在终端输入
//按顺序输入:
conda create -n tensorflow python=3.6
source activate tensorflow
pip install tensorflow==1.14
pip install Keras==2.2.5
然后再在pycharm中重新加载这个新建的环境就可以了
这里补充速度过慢的问题解决方法
pip install keras -i http://pypi.douban.com/simple --trusted-host pypi.douban.com