【问题标题】:Train Keras LSTM model with a variable number of features训练具有可变数量特征的 Keras LSTM 模型
【发布时间】:2018-06-25 09:31:37
【问题描述】:

我正在 Keras 中训练一个 seq-to-seq 自动编码器,我的输入是 (num_examples, time_step, num_features)。问题是,num_features 并不是所有示例都相同,此外,我将来会获得更多未知 num_feature 大小的示例。

到目前为止我的代码是:

    # model architecture
    inputs = Input(shape=data.shape[1:])

    encoded1 = LSTM(32, return_sequences=True)(inputs)
    encoded2 = LSTM(32)(encoded1)

    latent_space = Dense(encoding_size)(encoded2)

    decoded1 = RepeatVector(1)(latent_space)
    decoded2 = LSTM(encoding_size, return_sequences=True)(decoded1)

    sequence_autoencoder = Model(inputs, decoded2)

我尝试使用:inputs = Input(shape=(1, None)),但它会引发错误。关于如何解决这个问题的任何想法?

【问题讨论】:

    标签: keras lstm recurrent-neural-network autoencoder


    【解决方案1】:

    在使用 lstm 时,可以通过在输入形状中将 None 设置为 timestep 来处理不同大小的输入。

    inputs = Input(shape=(BATCH_SIZE,None,channels))
    

    通过这种方式,您可以向 LSTM 提供可变大小的输入。

    【讨论】:

    • 我不完全理解这个解决方案.. 这只适用于分类问题吗?那么时间序列呢,时间步长是明确的?
    • @robertotomás 该解决方案也适用于时间序列预测。这个想法是为推理提供可变大小的序列。
    • 这似乎是一个变量steps,而不是features
    猜你喜欢
    • 2020-02-18
    • 2018-01-30
    • 2018-11-29
    • 2018-01-08
    • 1970-01-01
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多