Keras作为Tensorflow封装的接口API,受到Tensorflow版本变化的影响,也是困扰基于Tensorflow开发者”梦魇“。把新遇到的兼容问题解决过程分享出来,问题描述:
在使用Keras是报错: “from keras.layers import LSTM 用pycharm要报错,没有包可导入“。
from keras.models import Sequential #Sequential 用于初始化神经网络 from keras.layers import Dense #Dense 用于添加全连接的神经网络层 from keras.layers import LSTM #LSTM 用于添加长短期内存层 Unresolved import LSTM
问题原因是Keras与TensorFlow兼容问题,详见 [2] ,解决方案:
首先查看当前Keras与TensorFlow版本,如下所示:
pip list Keras 2.4.3 Keras-Applications 1.0.8 Keras-Preprocessing 1.1.2 ... ... tensorboard 1.13.1 tensorflow 1.13.2 tensorflow-estimator 1.13.0
当时默认安装Keras版本是2.4.3,Tensorflow指定安装1.13.1。
然后卸载当前Keras,安装对应的版本:
pip uninstall keras pip install -i https://pypi.tuna.tsinghua.edu.cn/simple Keras==2.3.1
附兼容列表(部分):
参考:
[1]《Keras与TensorFlow对应版本一览》 CSDN博客, A_Mute dear, 2020.07
[2] Environments FloydHub
Be First to Comment