如何从LSTM自动编码器重构未指定长度的序列?

时间:2020-06-01 12:51:14

标签: python tensorflow keras lstm autoencoder

from keras import backend as K  
.... other dependencies .....
input_ae = Input(shape=(None, 2))  # shape: time_steps, n_features
LSTM1 = LSTM(units=128, return_sequences=True, activation = 'relu')(input_ae)
LSTM2 = LSTM(units=64, return_sequences=False, activation= 'relu')(LSTM1)
bottleneck = RepeatVector(n=K.shape(input_ae)[1])(LSTM2) # bottleneck layer
LSTM3 = LSTM(units=64, return_sequences=True)(bottleneck)
LSTM4 = LSTM(units=128, return_sequences=True, activation = 'relu')(LSTM3)
output = TimeDistributed(Dense(units=2))(LSTM4)


model = Model(input_ae, outputs=output) 
model.compile(optimizer='adam', loss='mse')

因此LSTM4的形状为[None,None,128],其中第一个值表示样本数,第二个表示时间步长,第三个表示特征数。我想重建具有2个特征但序列长度未指定的序列。问题出在TimeDIstributed层,长错误以“ OperatorNotAllowedInGraphError结尾:在图形执行中不允许使用tf.Tensor作为Python bool。请使用Eager执行或使用@tf装饰此函数功能。” ...有什么想法吗?

0 个答案:

没有答案