【问题标题】:Encoder-Decoder for Trajectory Prediction [closed]用于轨迹预测的编码器-解码器
【发布时间】:2021-03-23 22:01:55
【问题描述】:

我需要使用编码器-解码器结构来预测 2D 轨迹。由于几乎所有可用的教程都与 NLP(使用稀疏向量)相关,因此我不确定如何使解决方案适应连续数据。

除了我对序列到序列模型的无知之外,embedding 的单词处理让我更加困惑。我有一个由 3,000,000 个样本组成的数据集,每个样本都有 x-y 坐标 (-1, 1) 和 125 观测值,这意味着每个样本的形状是 (125, 2)。我以为我可以将其视为 125 个单词,其中包含 2 维已经嵌入的单词,但是 Keras Tutorial 中的编码器和解码器期望 3D 数组为 (num_pairs, max_english_sentence_length, num_english_characters)。

我怀疑我需要用这个模型单独训练每个样本(125, 2),就像谷歌的搜索栏只写一个单词一样。

据我了解,编码器是many-to-one 类型模型,解码器是one-to-many 类型模型。我需要将内存状态c 和隐藏状态h 作为向量(?)。然后我应该使用这些向量作为解码器的输入,并提取我确定的 (x,y) 形状的预测作为编码器输出。

如果有人能在我的数据集的形状上给出一个编码器 - 解码器 LSTM 架构的例子,我将非常感激,特别是在编码器 - 解码器输入和输出所需的维度方面,如果可能的话,特别是在 Keras 模型上。

【问题讨论】:

    标签: keras lstm encoder decoder encoder-decoder


    【解决方案1】:

    我假设您想用之前的 125 个时间步来预测 50 个时间步(例如)。我给了你最基本的时间序列编码器-解码器结构,但它可以改进(例如Luong Attention)。

    from tensorflow.keras import layers,models
    
    input_timesteps=125
    input_features=2
    output_timesteps=50
    output_features=2
    units=100
    
    #Input
    encoder_inputs = layers.Input(shape=(input_timesteps,input_features))
    
    #Encoder
    encoder = layers.LSTM(units, return_state=True, return_sequences=False)
    encoder_outputs, state_h, state_c = encoder(encoder_inputs) # because return_sequences=False => encoder_outputs=state_h
    
    #Decoder
    decoder = layers.RepeatVector(output_timesteps)(state_h)
    decoder_lstm = layers.LSTM(units, return_sequences=True, return_state=False)
    decoder = decoder_lstm(decoder, initial_state=[state_h, state_c])
    
    
    #Output
    out = layers.TimeDistributed(Dense(output_features))(decoder)
    
    model = models.Model(encoder_inputs, out)
    

    所以这里的核心思想是:

    1. 将时间序列编码为两种状态:state_h 和state_c。查看this 了解 LSTM 单元的工作。
    2. 重复state_h要预测的时间步数
    3. 使用由编码器计算初始状态的 LSTM 进行解码
    4. 使用密集层来确定每个时间步所需的特征数量

    我建议您测试我们的架构并使用model.summary() 和tf.keras.utils.plot_model(mode,show_shapes=True) 将它们可视化。它为您提供了很好的表示,例如总结:

    Layer (type)                    Output Shape         Param #     Connected to                     
    ==================================================================================================
    input_5 (InputLayer)            [(None, 125, 2)]     0                                            
    __________________________________________________________________________________________________
    lstm_8 (LSTM)                   [(None, 100), (None, 41200       input_5[0][0]                    
    __________________________________________________________________________________________________
    repeat_vector_4 (RepeatVector)  (None, 50, 100)      0           lstm_8[0][1]                     
    __________________________________________________________________________________________________
    lstm_9 (LSTM)                   (None, 50, 100)      80400       repeat_vector_4[0][0]            
                                                                     lstm_8[0][1]                     
                                                                     lstm_8[0][2]                     
    __________________________________________________________________________________________________
    time_distributed_4 (TimeDistrib (None, 50, 2)        202         lstm_9[0][0]                     
    ==================================================================================================
    Total params: 121,802
    Trainable params: 121,802
    Non-trainable params: 0
    __________________________________________________________________________________________________
    

    以及绘制的模型:

    【讨论】:

      猜你喜欢
      • 2020-10-03
      • 2020-02-10
      • 2011-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多