【问题标题】:how to choose LSTM 2-d input shape?如何选择 LSTM 2-d 输入形状?
【发布时间】:2017-12-08 15:18:30
【问题描述】:

我正在尝试将具有 22 个特征 (22,2000) 的一维信号 (1,2000) 输入 LSTM。
(一维信号以 200 赫兹的采样率为 10 秒)
我有808批。 (808, 22, 2000)

我看到 LSTM 接收 (batch_size, timestep, input_dim) 的 3D 张量形状。
那么我的输入形状是正确的吗?
: (batch_size = 808, timestep = 2000, input_dim = 3)

这是我的代码示例。

# data shape check
print(X_train.shape)
print(X_test.shape)
print(y_train.shape)
print(y_test.shape)
(727, 22, 2000)
(81, 22, 2000)
(727, 2)
(81, 2)

# Model Config
inputshape = (808,2000,2)  # 22 chanel, 2000 samples
lstm_1_cell_num = 20
lstm_2_cell_num = 20
inputdrop_ratio = 0.2
celldrop_ratio = 0.2

# define model
model = Sequential()
model.add(LSTM(lstm_1_cell_num, input_shape=inputshape, dropout=0.2, recurrent_dropout=0.2))
model.add(Dense(20))
model.add(LSTM(lstm_2_cell_num, dropout=0.2, recurrent_dropout=0.2))
model.add(Dense(2, activation='sigmoid'))
print(model.summary())
model.compile(loss='binary_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])

【问题讨论】:

  • 您没有在输入形状中包含批量大小

标签: machine-learning keras lstm recurrent-neural-network rnn


【解决方案1】:

第一个输入形状必须是 (22,2000) 并且批量大小应该在 fit 函数中给出。所以试试这个

inputshape = (22,2000)

model.fit(X_train, y_train,
          batch_size=808,
          epochs=epochs,
          validation_data=(X_test,y_test),
          shuffle=True)

【讨论】:

  • 我在 keras.io 中找到的,rnn 的输出形状应该是这样的 'if return_sequences: 3D tensor with shape (batch_size, timesteps, units).'。所以我想应该是(2000,22)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-27
  • 2019-01-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多