代码之家  ›  专栏  ›  技术社区  ›  shantanuo

张量对象没有属性keras_shape

  •  1
  • shantanuo  · 技术社区  · 5 年前

    创建模型时使用:

    model = Model(inputs=[input_text], outputs=pred)
    

    获取错误:

    attributeError:'tensor'对象没有属性''u keras'u shape'

    我试过的完整笔记本可以在这里找到… https://github.com/shantanuo/pandas_examples/blob/master/tensorflow/tf_learn.ipynb

    同样的代码是纯文本的… https://gist.github.com/shantanuo/4e35baba144ee658e4dd4d1f87e19f3a

    我想知道为什么我会得到一个错误,即使我使用的代码完全相同,如本博客所示:

    https://towardsdatascience.com/transfer-learning-using-elmo-embedding-c4a7e415103c

    预期输出-类似于:

    模型摘要为: _________________________________层(类型)输出形状参数#
    ====================================================输入层2(inputlayer)(无,1)0
    _________________________________ lambda_2(lambda)(无,1024)0
    _________________________________致密_3(致密)(无,256)262400
    _________________________________致密_4(致密)(无,1)257

    我尝试升级TensorFlow和Keras,但得到了相同的错误:

    !pip install --upgrade tensorflow
    
    1 回复  |  直到 5 年前
        1
  •  2
  •   dieKoderin    5 年前

    如果您更改此项:

    from keras.models import Model
    

    对此:

    from tensorflow.keras.models import Model
    

    你的代码会很好的。

    *或*

    改变这一点:

    from tensorflow.python.keras.layers import Input
    

    对此:

    from keras.layers import Input