Keras LSTM致密层多维输入
我正在尝试创建一个keras LSTM来预测时间序列.我的x_train的形状像3000,15,10(示例,时间步长,特征),y_train的形状像3000,15,1,我正在尝试建立多对多模型(每个序列10个输入特征使1个输出/序列).
I'm trying to create a keras LSTM to predict time series. My x_train is shaped like 3000,15,10 (Examples, Timesteps, Features), y_train like 3000,15,1 and I'm trying to build a many to many model (10 input features per sequence make 1 output / sequence).
我正在使用的代码是这样:
The code I'm using is this:
model = Sequential()
model.add(LSTM(
10,
input_shape=(15, 10),
return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(
100,
return_sequences=True))
model.add(Dropout(0.2))
model.add(Dense(1, activation='linear'))
model.compile(loss="mse", optimizer="rmsprop")
model.fit(
X_train, y_train,
batch_size=512, nb_epoch=1, validation_split=0.05)
但是,在使用时,我无法拟合模型:
However, I can't fit the model when using :
model.add(Dense(1, activation='linear'))
>> Error when checking model target: expected dense_1 to have 2 dimensions, but got array with shape (3000, 15, 1)
或以这种方式格式化时:
or when formatting it this way:
model.add(Dense(1))
model.add(Activation("linear"))
>> Error when checking model target: expected activation_1 to have 2 dimensions, but got array with shape (3000, 15, 1)
我已经尝试在添加密集层之前展平模型(model.add(Flatten())
),但这只是给了我ValueError: Input 0 is incompatible with layer flatten_1: expected ndim >= 3, found ndim=2
.这使我感到困惑,因为我认为我的数据实际上是3维的,不是吗?
I already tried flattening the model ( model.add(Flatten())
) before adding the dense layer but that just gives me ValueError: Input 0 is incompatible with layer flatten_1: expected ndim >= 3, found ndim=2
. This confuses me because I think my data actually is 3 dimensional, isn't it?
代码源自 https://github.com/Vict0rSch/deep_learning /tree/master/keras/recurrent