[英]ValueError: Input 0 of layer lstm_17 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [None, 128]
Here is the code:这是代码:
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding, LSTM, RepeatVector, Dense, Reshape
Model = Sequential([
Embedding(vocab_size, 256, input_length=49),
LSTM(256, return_sequences=True),
LSTM(128, return_sequences=False),
LSTM(128),
Reshape((128, 1)),
Dense(vocab_size, activation='softmax')
])
And this is the error message:这是错误消息:
ValueError: Input 0 of layer lstm_11 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [None, 128]
I am using tensorflow 1.15.0 and running it on Google Colab.我正在使用 tensorflow 1.15.0 并在 Google Colab 上运行它。 How can I fix it.我该如何解决。
As also said by Marco in the comments, the decoder expects 3d but it gets 2d, so applying a RepeatVector layer before the decoder worked.正如 Marco 在评论中所说,解码器需要 3d,但它得到 2d,因此在解码器工作之前应用 RepeatVector 层。 The corrected Model:修正后的模型:
Model = Sequential([
Embedding(vocab_size, 256, input_length=49),
LSTM(256, return_sequences=True),
LSTM(128, return_sequences=False),
RepeatVector(1),
LSTM(128),
Dense(vocab_size, activation='softmax')
])
I added RepeatVector layer to make the output shape 3D, and removed the Reshape layer since now it has no use.我添加了 RepeatVector 层使输出形状为 3D,并删除了 Reshape 层,因为它现在没有用了。
Thanks Marco for the help!感谢马可的帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.