【问题标题】:AttributeError: module 'tensorflow' has no attribute 'get_default_graph'. I am getting this error when adding a new layer to a modelAttributeError:模块“tensorflow”没有属性“get_default_graph”。向模型添加新层时出现此错误
【发布时间】:2019-09-17 17:59:55
【问题描述】:
ml = Sequential()
ml.add(LSTM(64,dropout=0.5, recurrent_dropout=0.5,return_sequences=True))

这给了我一个错误:AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

ml 是模型的名称。我无法向模型添加任何层。请帮忙。

我正在使用的依赖项是:

  • 张量流:2.0.0-beta1
  • Keras:2.2.4
  • Python:3.7.3

【问题讨论】:

    标签: python-3.x tensorflow keras


    【解决方案1】:

    升级到最新的Tensorflow版本而不是Beta版本。并使用下面提到的导入功能。

    要安装:

    pip install tensorflow==2.2.0
    #OR
    pip install --upgrade tensorflow
    

    导入:

    import tensorflow as tf
    from tensorflow.keras.models import Sequential
    from tensorflow.keras.layers import LSTM
    
    ml = Sequential()
    ml.add(LSTM(64,dropout=0.5, recurrent_dropout=0.5,return_sequences=True)) 
    

    您的代码现在应该可以正常工作了。

    【讨论】:

      猜你喜欢
      • 2019-08-09
      • 2020-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-25
      • 1970-01-01
      相关资源
      最近更新 更多