Python 名称';获取默认图形';没有定义
我无法在代码中使用Python 名称';获取默认图形';没有定义,python,tensorflow,keras,jupyter-notebook,tensorflow2.0,Python,Tensorflow,Keras,Jupyter Notebook,Tensorflow2.0,我无法在代码中使用model=Sequential()。我正在一个名为mllearn的环境中运行jupyter笔记本中的代码。我收到一个名为name'get\u default\u graph'的错误,该错误未定义 --------------------------------------------------------------------------- NameError Traceback (most recent c
model=Sequential()
。我正在一个名为mllearn
的环境中运行jupyter笔记本中的代码。我收到一个名为name'get\u default\u graph'的错误,该错误未定义
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
in
----> 1 md = bidirectional_lstm_models(seq_length, vocab_size)
2 md.summary()
in bidirectional_lstm_models(seq_len, vocab_size)
1 def bidirectional_lstm_models(seq_len, vocab_size):
2 model = Sequential()
----> 3 model.add(Bidirectional(LSTM(256, activation="relu"), input_shape=(seq_len, vocab_size)))
4 model.add(Dropout(0.6))
5 model.add(Dense(vocab_size))
~/opt/anaconda3/envs/ml-learn/lib/python3.7/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
89 warnings.warn('Update your `' + object_name + '` call to the ' +
90 'Keras 2 API: ' + signature, stacklevel=2)
---> 91 return func(*args, **kwargs)
92 wrapper._original_function = func
93 return wrapper
~/opt/anaconda3/envs/ml-learn/lib/python3.7/site-packages/keras/layers/recurrent.py in __init__(self, units, activation, recurrent_activation, use_bias, kernel_initializer, recurrent_initializer, bias_initializer, unit_forget_bias, kernel_regularizer, recurrent_regularizer, bias_regularizer, activity_regularizer, kernel_constraint, recurrent_constraint, bias_constraint, dropout, recurrent_dropout, implementation, return_sequences, return_state, go_backwards, stateful, unroll, **kwargs)
2176 dropout=dropout,
2177 recurrent_dropout=recurrent_dropout,
-> 2178 implementation=implementation)
2179 super(LSTM, self).__init__(cell,
2180 return_sequences=return_sequences,
~/opt/anaconda3/envs/ml-learn/lib/python3.7/site-packages/keras/layers/recurrent.py in __init__(self, units, activation, recurrent_activation, use_bias, kernel_initializer, recurrent_initializer, bias_initializer, unit_forget_bias, kernel_regularizer, recurrent_regularizer, bias_regularizer, kernel_constraint, recurrent_constraint, bias_constraint, dropout, recurrent_dropout, implementation, **kwargs)
1833 implementation=1,
1834 **kwargs):
-> 1835 super(LSTMCell, self).__init__(**kwargs)
1836 self.units = units
1837 self.activation = activations.get(activation)
~/opt/anaconda3/envs/ml-learn/lib/python3.7/site-packages/keras/engine/base_layer.py in __init__(self, **kwargs)
130 if not name:
131 prefix = self.__class__.__name__
--> 132 name = _to_snake_case(prefix) + '_' + str(K.get_uid(prefix))
133 self.name = name
134
~/opt/anaconda3/envs/ml-learn/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py in get_uid(prefix)
72 """
73 global _GRAPH_UID_DICTS
---> 74 graph = get_default_graph()
75 if graph not in _GRAPH_UID_DICTS:
76 _GRAPH_UID_DICTS[graph] = defaultdict(int)
NameError: name 'get_default_graph' is not defined
我尝试过的事情:
在文件tensorflow\u backend.py
中,我试图修改为:tf.compat.v1.get\u default\u graph
。我还试图修改我正在处理的文件:tensorflow.keras.models
importSequential
。我尝试了两者的结合。这些都不起作用
如果有人知道这件事,请帮帮我 这个问题有很多问题(至少对我来说是这样)。我为解决这个问题所做的是:
bash~/Downloads/Anaconda3-2019.10-MacOSX-x86_64.sh
。确保根据您下载的版本更改2019.10
李>
conda列表
或任何conda,确保安装了conda
-版本
conda
没有为您显示,请尝试重新启动您的终端。如果不起作用,请尝试eval“$(/home/msarahan/mc3\u dummy/bin/conda shell.bash hook)”
。将目录替换为您的目录,然后运行conda init
。如果不起作用,请运行以下命令:export PATH=“/Users/myname/anaconda2/bin:$PATH”
conda init
操作,它将询问哪个shell。我使用的是fish
,所以我选择了fish
conda create-n envName
。用您喜欢的任何环境名称替换envName
conda Activate envName
jupyter
(我的案例:Visual Studio代码),请运行conda安装-c anaconda jupyter
conda Install keras
和conda Install tensorflow
(我的案例)李>
pip show keras
和pip show tensorflow
来验证您的安装为了缓解我的问题,我正面临着kernal公司出人意料的倒闭。因此,我关闭了我的mac电脑,并在一段时间后打开它。如果您仍然无法修复这样的错误(我打赌我们都将Mac留在sleep lol上)。您使用的是TensorFlow和Keras的哪个版本?我使用的是1.13.1。我想我应该使用低于2.0的版本来实现这一点。然后添加完整的回溯。新手,不太确定如何做到这一点:(这是您收到的完整错误消息,包括任何回溯(它以“回溯(最近的调用最后):”开头)