不支持 TensorFlow 2.0 的 Keras。我们建议使用“tf.keras”,或者降级到 TensorFlow 1.14

Keras that does not support TensorFlow 2.0. We recommend using `tf.keras`, or alternatively, downgrading to TensorFlow 1.14

我有关于(不支持 TensorFlow 2.0 的 Keras。我们建议使用 tf.keras,或者降级到 TensorFlow 1.14。)任何建议的错误。

感谢

import keras
#For building the Neural Network layer by layer
from keras.models import Sequential
#To randomly initialize the weights to small numbers close to 0(But not 0)
from keras.layers import Dense

classifier=tf.keras.Sequential()

classifier.add(Dense(output_dim = 6, init = 'uniform', activation = 'relu', input_dim = 11))




RuntimeError: It looks like you are trying to use a version of multi-backend Keras that does not support TensorFlow 2.0. We recommend using `tf.keras`, or alternatively, downgrading to TensorFlow 1.14.

您只需更改顶部的导入:

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

classifier = Sequential()
classifier.add(Dense(6, init = 'uniform', activation = 'relu', input_dim = 11))

TensorFlow 2.0+ 仅兼容 Keras 2.3.0+,因此如果您想使用 Keras 2.2.5-,则需要 TensorFlow 1.15.0-。或者,是的,您可以执行 from tensorflow.keras import ...,但这根本不会使用您的 keras 包,您最好卸载它。

我运行遇到了同样的问题。使用以下命令将我的 TensorFlow 降级到版本 1.14:

!pip install tensorflow==1.14.0

修正了错误。

如果你想使用 tensorflow 2.0+ 你必须有 keras 2.3+
尝试升级你的 keras 它对我有用:

pip install -U keras

或者你可以指定keras版本为2.3

第一个单元格中的这行代码对我有用

%tensorflow_version 1.x

我通过 运行

解决了这个问题
pip install --ignore-installed --upgrade keras

首先,导入tensorflow:

import tensorflow as tf

接下来,代替这个,

classifier.add(Dense(output_dim = 6, init = 'uniform', activation = 'relu', input_dim = 11))

使用:

classifier.add(tf.keras.layers.Dense(output_dim = 6, init = 'uniform', activation = 'relu', input_dim = 11))

如果有效请告诉我。