ValueError:检查目标时出错:预期lstm_27具有2个维,但数组的形状为(1,11,1)

时间:2019-05-21 11:29:31

标签: keras lstm autoencoder

我正在尝试将keras.io网站中提到的带有序列输入的简单LSTM自动编码器并入。在LSTM层输入处引发错误。

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

def autoencoder(timesteps,input_dim):
    inputs = Input(shape=(timesteps, input_dim))
    encoded = LSTM(300)(inputs)

    decoded = RepeatVector(timesteps)(encoded)
    decoded = LSTM(input_dim, return_sequences=True)(decoded)

    encoder = Model(inputs, encoded)
    encoder.compile(optimizer='adam',loss='mse')
    return encoder

sequence = np.array([522,76,2,35,387,13,121,144,98,33,400]).reshape((1,11,1))
model = autoencoder(11,1)
model.fit(sequence,sequence,epochs=100,batch_size=4,verbose=1)

错误:

  

ValueError:检查目标时出错:预期lstm_29具有2   尺寸,但数组的形状为(1、11、1)

0 个答案:

没有答案