ValueError: Error when checking target: expected lstm_27 to have 2 dimensions, but got array with shape (1, 11, 1)

冷暖自知 提交于 2019-12-11 00:16:05

问题


I am trying to incorporate a simple LSTM autoencoder mentioned in the keras.io website with a sequence input. It is throwing an error at the LSTM layer input.

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)

The error:

ValueError: Error when checking target: expected lstm_29 to have 2 dimensions, but got array with shape (1, 11, 1)

来源:https://stackoverflow.com/questions/56237313/valueerror-error-when-checking-target-expected-lstm-27-to-have-2-dimensions-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!