Tensorflow compatibility with Keras

淺唱寂寞╮ 提交于 2021-02-20 18:47:00

问题


I am using Python 3.6 and Tensorflow 2.0, and have some Keras codes:

import keras
from keras.models import Sequential
from keras.layers import Dense

model = Sequential()
model.add(Dense(1))
model.compile(optimizer='adam',loss='mean_squared_error',metrics=['accuracy'])

However I got the error: "Keras requires TensorFlow 2.2 or higher. Install TensorFlow via pip install tensorflow" when trying to run it.

I checked on https://keras.io/, it says Keras was built on Tensorflow 2.0. So I am confused. What exact version of Tensorflow does latest Keras support? and how to fix the above error? Thanks!


回答1:


The problem is that the latest keras version (2.4.x) is just a wrapper on top of tf.keras, which I do not think is that you want, and this is why it requires specifically TensorFlow 2.2 or newer.

What you can do is install Keras 2.3.1, which supports TensorFlow 2.x and 1.x, and is the latest real releases of Keras. You can also install Keras 2.2.4 which only supports TensorFlow 1.x. You can install specific versions like this:

pip install --user keras==2.3.1



回答2:


That configuration can be tricky. How about you use keras inside tensorflow? I think they are more likely to be compatible each other.

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense



回答3:


Just check Tensorflow and Keras compatibility:

Check this link for more info.



来源:https://stackoverflow.com/questions/62690377/tensorflow-compatibility-with-keras

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!