不支持 TensorFlow 2.0 的 Keras。我们建议使用“tf.keras”,或者降级到 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.

原文由 Dean 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 988
2 个回答

您只需要更改顶部的导入:

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

原文由 nickyfot 发布,翻译遵循 CC BY-SA 4.0 许可协议

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

原文由 OverLordGoldDragon 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题