如何在keras LSTM Autoencoder中获取学习的表示

问题描述 投票:0回答:1

我有一个多层LSTM自动编码器,其输入是一个20步时间序列,有4个属性。

    model = Sequential()
    model.add(CuDNNLSTM(128, input_shape=(20, 4), return_sequences=True))  # encode 1
    model.add(CuDNNLSTM(256, return_sequences=True))  # encode 2
    model.add(CuDNNLSTM(512, return_sequences=True))  # encode 3 -- our final vector
    model.add(CuDNNLSTM(256, return_sequences=True))  # decode 1
    model.add(CuDNNLSTM(128, return_sequences=True))  # decode 2
    model.add(TimeDistributed(Dense(4)))
    model.compile(optimizer='adam', loss='mse')

当我将输出层设置为编码层#3时,输出的形状为(1,20,512)。

如何从此图层获取形状矢量(1,512)以用作输入时间序列的学习表示?

我是否正确地说形状是(1,20,512),因为该层为每个时间步产生一个输出向量,在这种情况下我应该使用最后一个输出向量?

python keras deep-learning lstm autoencoder
1个回答
1
投票

由于设置了return_sequences=True,LSTM层将为序列的每个时间步输出一个向量。

如果您只对最后一个序列元素感兴趣,可以使用最后一个512向量。但是,如果您不需要处理以下图层,您可能只需为您感兴趣的图层设置return_sequences=False,它将直接输出您想要的形状(1,512)

© www.soinside.com 2019 - 2024. All rights reserved.