使用以下方法构建模型时:
model = Model(inputs=[input_text], outputs=pred)
得到一个错误:
AttributeError: 'Tensor' object has no attribute '_keras_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
预期的输出 - 像这样:
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 但得到同样的错误:
!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
关于tensorflow - 张量对象没有属性 keras_shape,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54614299/