Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
属性错误:模块';tensorflow';没有属性';获取默认图形';_Tensorflow - Fatal编程技术网

属性错误:模块';tensorflow';没有属性';获取默认图形';

属性错误:模块';tensorflow';没有属性';获取默认图形';,tensorflow,Tensorflow,给出以下输出 import tensorflow as tf from keras.models import Sequential from keras.layers import Dense model = Sequential([ Dense(32, activation='relu', input_shape=(5038,)), Dense(32, activation='relu'), Dense(881, activation='sigmoid'),]) mode

给出以下输出

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

model = Sequential([    Dense(32, activation='relu', input_shape=(5038,)),    Dense(32, activation='relu'),    Dense(881, activation='sigmoid'),])
model.compile(optimizer='sgd', loss='binary_crossentropy', metrics=['accuracy'])
hist = model.fit(X_train, Y_train,          batch_size=32, epochs=100,          validation_data=(X_val, Y_val))

为什么会出现此错误?

看起来您正在使用TensorFlow 2.0(或更新版本)。TensorFlow>=2.0在
tf.Keras
下提供了对Keras的全面内置支持。如上所述,TensorFlow用户应使用
tf.keras
而不是keras模块

可以使用
tf.keras
以以下方式重写您的特定示例:

AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in _get_default_graph()
     65     try:
---> 66         return tf.get_default_graph()
     67     except AttributeError:

AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
5 frames
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in _get_default_graph()
     67     except AttributeError:
     68         raise RuntimeError(
---> 69             'It looks like you are trying to use '
     70             'a version of multi-backend Keras that '
     71             'does not support TensorFlow 2.0. We recommend '

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.

有关更多信息,请参见此处的tf.keras教程:

看起来您正在使用TensorFlow 2.0(或更新版本)。TensorFlow>=2.0在
tf.Keras
下提供了对Keras的全面内置支持。如上所述,TensorFlow用户应使用
tf.keras
而不是keras模块

可以使用
tf.keras
以以下方式重写您的特定示例:

AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in _get_default_graph()
     65     try:
---> 66         return tf.get_default_graph()
     67     except AttributeError:

AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
5 frames
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py in _get_default_graph()
     67     except AttributeError:
     68         raise RuntimeError(
---> 69             'It looks like you are trying to use '
     70             'a version of multi-backend Keras that '
     71             'does not support TensorFlow 2.0. We recommend '

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.
有关更多信息,请参见此处的tf.keras教程: