输入数据(X)的形状为(2000, 7, 7, 512)

网是

visible = Input(shape=(7,7,512))
Lstm = LSTM(units=22, return_sequences=True)(visible)
Dense_1 = Dense(4096)(Lstm)
Dense_2 = Dense(512 ,activation='sigmoid')(Dense_1)
Dense_3 = Dense(5, activation='sigmoid')(Dense_2)
model = Model(input = visible, output=Dense_3)


错误是:
ValueError: Input 0 is incompatible with layer lstm_1: expected ndim=3, found ndim=4

lstm和其他图层的input_shape应该是什么?

最佳答案

LSTM输入层必须是3D,尺寸为:


样品,
时间步长,
特征


像这样尝试:

from keras.models import Model
from keras.layers import Input
from keras.layers import LSTM
from keras.layers import Dense
import numpy as np

# define model
X = np.random.rand(2000, 7, 7, 512)
X = X.reshape(2000, 49, 512)

visible = Input(shape=(49,512))
Lstm = LSTM(units=22, return_sequences=True)(visible)
Dense_1 = Dense(4096)(Lstm)
Dense_2 = Dense(512 ,activation='sigmoid')(Dense_1)
Dense_3 = Dense(5, activation='sigmoid')(Dense_2)
model = Model(input = visible, output=Dense_3)




LSTM输入层由第一个隐藏层上的shape参数定义。

它采用两个值的元组来定义时间步和特征的数量。

假定样本数为1或更多,在这里我认为2000是样本数。

关于python - 如何在Keras中以(2000,7,7,512)张量形状填充LSTM网络?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54354281/

10-12 19:32