问题
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