LSTM自动编码器目标形状问题

问题描述

我尝试运行自动编码器LSTM的示例,但是代码不一致并且发生错误

enter link description here

print(f'X Training shape: {X_train.shape}')
print(f'X Testing shape: {X_test.shape}')

model = Sequential()
model.add(LSTM(128,return_sequences=False,input_shape=(X_train.shape[1],X_train.shape[2])))
model.add(Dropout(rate=0.2))
model.add(RepeatVector(X_train.shape[1]))
model.add(LSTM(128,return_sequences=True))
model.add(Dropout(rate=0.2))
model.add(Timedistributed(Dense(X_train.shape[2])))
model.compile(optimizer='adam',loss='mae')
model.summary()

history = model.fit(X_train,y_train,epochs=1,batch_size=32,validation_split=0.1,callbacks=[keras.callbacks.EarlyStopping(monitor='val_loss',patience=3,mode='min')],shuffle=False)

输出错误是:

X Training shape: (7029,30,1)
X Testing shape: (1734,1)

_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
lstm_46 (LSTM)               (None,128)               66560     
_________________________________________________________________
dropout_46 (Dropout)         (None,128)               0         
_________________________________________________________________
repeat_vector_26 (RepeatVect (None,128)           0         
_________________________________________________________________
lstm_47 (LSTM)               (None,128)           131584    
_________________________________________________________________
dropout_47 (Dropout)         (None,128)           0         
_________________________________________________________________
time_distributed_20 (Timedis (None,1)             129       
=================================================================
Total params: 198,273
Trainable params: 198,273
Non-trainable params: 0
_________________________________________________________________


...
ValueError: Error when checking target: expected time_distributed_22 to have shape (30,1) but got array with shape (1,1)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)