简体   繁体   English

如何解决“看起来您正在尝试使用不支持 TensorFlow 2.0 的多后端 Keras 版本”

[英]how to solve ''looks like you are trying to use a version of multi-backend Keras that does not support TensorFlow 2.0''

I am using tensorflow 2 version for running a sequentional model.我正在使用 tensorflow 2 版本来运行序列模型。 I am not sure why it does not support tensorflow2.我不确定为什么它不支持 tensorflow2。 I also checked the same question , but it doesn't help.我也检查了同样的问题,但没有帮助。 can anyone help me to correct the code?谁能帮我更正代码?

from sklearn.model_selection import train_test_split
import tensorflow
import keras
from tensorflow.keras import layers
from tensorflow.keras import optimizers
from tensorflow.keras import callbacks
from tensorflow.python.keras.layers import Input, Dense, Dropout

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import BatchNormalization
from keras.layers.convolutional import Conv2D
from keras.layers.convolutional import MaxPooling2D, AveragePooling2D
from keras.layers.core import Activation
from tensorflow.keras.layers import Flatten
from tensorflow.keras.layers import Input
from tensorflow.keras import optimizers
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras import datasets, layers, models
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.utils import plot_model
from tensorflow.keras.models import load_model, Model
from tensorflow.keras.callbacks import EarlyStopping

model = Sequential()
model.add(Conv2D(input_shape=(32,32,4),filters=64,kernel_size=(3,3),padding="same", activation="relu"))
model.add(Conv2D(filters=64,kernel_size=(3,3),padding="same", activation="relu"))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))
model.add(Conv2D(filters=128, kernel_size=(3,3), padding="same", activation="relu"))
model.add(Conv2D(filters=128, kernel_size=(3,3), padding="same", activation="relu"))
model.add(MaxPooling2D(pool_size=(2,2),strides=(2,2)))

model.add(Flatten())
model.add(Dense(units=1024,activation="relu"))
model.add(Dense(units=1024,activation="relu"))
model.add(Dense(units=1, activation="linear"))

#compile model
optimizer = tensorflow.keras.optimizers.Adam(learning_rate=0.0001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
model.compile(loss='mean_squared_error',
                optimizer=optimizer,
                metrics=['mae'])

error:错误:

Traceback (most recent call last):
  File "/appl/soft/ai/miniconda3/envs/tensorflow-2.0.0/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 66, in _get_default_graph
    return tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

During handling of the above exception, another exception occurred:

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.

I managed to run the code by editing the section for importing the libraries:我设法通过编辑导入库的部分来运行代码:

from tensorflow.python.keras.layers import Input, Dense, Flatten, Dropout, Conv2D, MaxPooling2D
from tensorflow.python.keras.models import Model

from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.layers import BatchNormalization
from tensorflow.python.keras import optimizers                                                                                                                                                             from tensorflow.python.keras.callbacks import EarlyStopping

import tensorflow as tf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让 Keras 在 Anaconda 中使用 Tensorflow 后端? - How to make Keras use Tensorflow backend in Anaconda? 不支持 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 如何使用低版本的 keras 和 tensorflow - How to use lower version of keras and tensorflow 如何在 TensorFlow 2.0 keras 和 MLFlow 中使用 tf.lookup 表 - How to use tf.lookup tables with TensorFlow 2.0 keras and MLFlow 如何在 Tensorflow 2.0/Keras 中正确使用 CategoricalCrossentropy loss 进行图像分割? - How to properly use CategoricalCrossentropy loss for image segmentation in Tensorflow 2.0/Keras? Keras/Tensorflow 如何使用 GPU 和 CPU? - How does Keras/Tensorflow use GPU and CPU? Keras 的 TensorFlow 后端是否依赖于 Eager Execution? - Does the TensorFlow backend of Keras rely on the eager execution? 如何在拟合模型时在keras / tensorflow中使用多线程? - How to use multi threading in keras/tensorflow when fitting a model? 将Keras(Tensorflow后端)与移动GPU(笔记本电脑)结合使用 - Use Keras (Tensorflow backend) with mobile GPU (laptop) 无法在 Tensorflow 2.0 中使用 vggface-keras - Cannot use vggface-keras in Tensorflow 2.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM