ImportError: cannot import name ‘export_saved_model‘ from ‘tensorflow.python.keras.saving.saved_mode

项目场景:

在尝试搭建深度学习环境的时候遭遇这个问题。 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
  • 8
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值