我正在尝试构建一个LSTM自动编码器,如图here所示 我的代码:
from keras.layers import Input, LSTM, RepeatVector
from keras.models import Model
inputs = Input(shape=(window_length, input_dim))
encoded = LSTM(latent_dim)(inputs)
decoded = RepeatVector(window_length)(encoded)
decoded = LSTM(input_dim, return_sequences=True)(decoded)
model = Model(inputs, decoded)
model.fit(batch_size=512)
数据集的形状为:(rows,window_length,input_dim) 当我尝试调用fit()时出现此错误:
ValueError: Cannot feed value of shape (512, 221) for Tensor u'lstm_2_target:0', which has shape '(?, ?, ?)'
这个模型很简单,我不明白是什么问题。
修改
模型摘要:
Layer (type) Output Shape Param #
=================================================================
input_1 (InputLayer) (None, 10, 221) 0
_________________________________________________________________
lstm_1 (LSTM) (None, 128) 179200
_________________________________________________________________
repeat_vector_1 (RepeatVecto (None, 10, 128) 0
_________________________________________________________________
lstm_2 (LSTM) (None, 10, 221) 309400
=================================================================
Total params: 488,600
Trainable params: 488,600
Non-trainable params: 0
答案 0 :(得分:0)
如果代码完全按照上述方式运行,则可能需要对其进行编译:
model.compile(optimizer='rmsprop', loss='mse', metrics=['acc', 'cosine_proximity'])