如何解决"AttributeError:模块'tensorflow'没有属性'get_default_graph'"? [英] How to fix "AttributeError: module 'tensorflow' has no attribute 'get_default_graph'"?
问题描述
我正在尝试运行一些代码来创建LSTM模型,但出现错误:
I am trying to run some code to create an LSTM model but i get an error:
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'
我的代码如下:
from keras.models import Sequential
model = Sequential()
model.add(Dense(32, input_dim=784))
model.add(Activation('relu'))
model.add(LSTM(17))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
我发现其他人也有类似的问题,他们更新了tensorflow,它可以正常工作;但我的是最新的,但仍然无法正常工作.我对使用keras和机器学习并不陌生,因此,如果这很愚蠢,我深表歉意!
I have found someone else with a similar problem and they updated tensorflow and it works; but mine is up to date and still does not work. I am new to using keras and machine learning so I apologise if this is something silly!
推荐答案
原来,我使用的是错误的版本(2.0.0a0),所以我重置为最新的稳定版本(1.13.1),并且可以使用.
Turns out I was using the wrong version (2.0.0a0), so i reset to the latest stable version (1.13.1) and it works.
这篇关于如何解决"AttributeError:模块'tensorflow'没有属性'get_default_graph'"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!