微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。