在 Keras 中使用 LSTM 将一系列向量映射到单个向量
Map series of vectors to single vector using LSTM in Keras
假设我有一个随时间变化的特征矢量,并希望将其映射到单个矢量以用作分类中的层。这将如何在 Keras 中实现?示例:
Input: <1.0, 2.0, 3.0> -> <1.1, 1.9, 3.2> -> ...
Output: <1.0, 0.0, 0.0, 2.0>
Keras 文档说 LSTM 对象具有 3 个维度,但我不确定在这种情况下如何表达。
LSTM 在 [batch_size, time_steps, input_dim]
中接受输入。在您的情况下,您可以将每个向量视为一个时间步长。因此,在具有两个时间步长的输入上将是:
[<1.0, 2.0, 3,0>, <1.1, 1.0, 3.2>] which maps to <1.0, 0.0, 0.0, 2.0>
举个例子:
input_dim = 3
num_steps = 2
model = Sequential()
model.add(LSTM(16, input_shape=(num_steps, input_dim)) # output 2d [batch_size, 16]
model.add(Dense(4)) # output [batch, 4]
# ... more layers
不要害怕阅读他们做得很好的文档。 https://keras.io/layers/recurrent/#lstm
假设我有一个随时间变化的特征矢量,并希望将其映射到单个矢量以用作分类中的层。这将如何在 Keras 中实现?示例:
Input: <1.0, 2.0, 3.0> -> <1.1, 1.9, 3.2> -> ...
Output: <1.0, 0.0, 0.0, 2.0>
Keras 文档说 LSTM 对象具有 3 个维度,但我不确定在这种情况下如何表达。
LSTM 在 [batch_size, time_steps, input_dim]
中接受输入。在您的情况下,您可以将每个向量视为一个时间步长。因此,在具有两个时间步长的输入上将是:
[<1.0, 2.0, 3,0>, <1.1, 1.0, 3.2>] which maps to <1.0, 0.0, 0.0, 2.0>
举个例子:
input_dim = 3
num_steps = 2
model = Sequential()
model.add(LSTM(16, input_shape=(num_steps, input_dim)) # output 2d [batch_size, 16]
model.add(Dense(4)) # output [batch, 4]
# ... more layers
不要害怕阅读他们做得很好的文档。 https://keras.io/layers/recurrent/#lstm