张量对象没有属性keras_shape [英] Tensor object has no attribute keras_shape
问题描述
使用以下方法建立模型时:
While building a model using:
model = Model(inputs=[input_text], outputs=pred)
遇到错误:
AttributeError:"Tensor"对象没有属性"_keras_shape"
AttributeError: 'Tensor' object has no attribute '_keras_shape'
我尝试过的完整笔记本可以在这里找到...> https://github.com/shantanuo/pandas_examples/blob/master/tensorflow/tf_learn.ipynb
The complete notebook that I tried can be found here... https://github.com/shantanuo/pandas_examples/blob/master/tensorflow/tf_learn.ipynb
这里是相同的纯文本代码... https://gist.github.com/shantanuo/4e35baba144ee658e4dd4d1f87e19f3a
And the same code in plain text here... https://gist.github.com/shantanuo/4e35baba144ee658e4dd4d1f87e19f3a
即使我使用与本博客中所示完全相同的代码,我也想知道为什么会出错:
I will like to know why am I getting an error even if I am using the exact same code as shown in this blog:
https://towardsdatascience.com/transfer-learning-using-elmo-embedding-c4a7e415103c
期望的输出-像这样:
模型摘要为:_________________________________________________________________图层(类型)输出形状参数#
================================================================ input_2(InputLayer)(无,1)0
_________________________________________________________________ lambda_2(Lambda)(无,1024)0
_________________________________________________________________ density_3(密集)(无,256)262400
_________________________________________________________________ density_4(Dense)(None,1)257
The model summary is: _________________________________________________________________ Layer (type) Output Shape Param #
================================================================= input_2 (InputLayer) (None, 1) 0
_________________________________________________________________ lambda_2 (Lambda) (None, 1024) 0
_________________________________________________________________ dense_3 (Dense) (None, 256) 262400
_________________________________________________________________ dense_4 (Dense) (None, 1) 257
我尝试升级tensorflow和keras,但收到相同的错误:
I tried to upgrade tensorflow and keras but getting the same error:
!pip install --upgrade tensorflow
推荐答案
如果您对此进行更改:
from keras.models import Model
对此:
from tensorflow.keras.models import Model
您的代码会没事的.
*或*
更改此:
from tensorflow.python.keras.layers import Input
对此:
from keras.layers import Input
这篇关于张量对象没有属性keras_shape的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!