且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

尝试在Keras中创建BLSTM网络时出现TypeError

更新时间:2023-12-02 17:06:40

您的问题出在以下三行中:

Your problem lies in these three lines:

BLSTM1 = layers.Bidirectional(layers.LSTM(128, input_shape=(8,40,96)))(merge_layer)
print(BLSTM1.shape)
BLSTM2 = layers.Bidirectional(layers.LSTM(128))(BLSTM1)

默认情况下,LSTM仅返回计算的最后一个元素-因此您的数据将失去其顺序性质.这就是前进层引发错误的原因.将此行更改为:

As a default, LSTM is returning only the last element of computations - so your data is losing its sequential nature. That's why the proceeding layer raises an error. Change this line to:

BLSTM1 = layers.Bidirectional(layers.LSTM(128, return_sequences=True))(merge_layer)
print(BLSTM1.shape)
BLSTM2 = layers.Bidirectional(layers.LSTM(128))(BLSTM1)

为了使第二个LSTM的输入也具有顺序性质.

In order to make the input to the second LSTM to have sequential nature also.

除此之外-我不想在中间模型层中使用input_shape,因为它是自动推断的.

Aside of this - I'd rather not use input_shape in middle model layer as it's automatically inferred.