Tensorflow与Keras的兼容性 [英] Tensorflow compatibility with Keras

查看:398
本文介绍了Tensorflow与Keras的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python 3.6和Tensorflow 2.0,并具有一些Keras代码:

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'])

但是我收到错误消息:"Keras需要TensorFlow 2.2或更高版本.通过pip install tensorflow"安装TensorFlow尝试运行它时.

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

我检查了 https://keras.io/,它说Keras是基于Tensorflow 2.0构建的. 所以我很困惑.最新的Keras支持什么版本的Tensorflow?以及如何解决以上错误?谢谢!

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!

推荐答案

问题是最新的keras版本(2.4.x)只是tf.keras之上的包装,我不认为这是您想要的,这就是为什么它特别需要TensorFlow 2.2或更高版本的原因.

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.

您可以做的是安装Keras 2.3.1,它支持TensorFlow 2.x和1.x,并且是Keras的最新实际发行版.您还可以安装仅支持TensorFlow 1.x的Keras 2.2.4.您可以安装以下特定版本:

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

这篇关于Tensorflow与Keras的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆