在keras中喂LSTM
feed LSTM in keras
我对keras很陌生。我想知道是否有人可以帮助我如何将我的脑电图数据输入 LSTM。我从 306 个通道进行了 1400 次试验,长度为 600 点。
1- 我想创建一个 LSTM 网络,在每个时间步 t,第一层接受所有通道的输入(所有 EEG 通道最初都被送入同一个 LSTM 层)
2- 还有另一个网络由几个 306 个 LSTM 组成,每个 LSTM 在第一层仅连接到一个输入通道,然后是第二个编码层
执行通道间分析,通过接收级联的输入
所有通道 LSTM 的输出向量。
谢谢
如果我没看错的话,代码应该是这样的:
def lstm_model():
hidden_units = 512 # may increase/decrease depending on capacity needed
timesteps = 600
input_dim = 306
num_classes = 10 # num of classes for ecg output
model = Sequential()
model.add(LSTM(hidden_units, input_shape=(timesteps, input_dim)))
model.add(Dense(num_classes))
adam = Adam(lr=0.001)
model.compile(loss='categorical_crossentropy', optimizer=adam, metrics=['accuracy'])
return model
def train():
xt = np.array([]) # input_data shape = (num_trials, timesteps, input_dim)
yt = np.array([]) # out_data shape = (num_trials, num_classes)
batch_size = 16
epochs = 10
model = lstm_model()
model.fit(xt, yt, epochs=epochs, batch_size=batch_size, shuffle=True)
我对keras很陌生。我想知道是否有人可以帮助我如何将我的脑电图数据输入 LSTM。我从 306 个通道进行了 1400 次试验,长度为 600 点。
1- 我想创建一个 LSTM 网络,在每个时间步 t,第一层接受所有通道的输入(所有 EEG 通道最初都被送入同一个 LSTM 层)
2- 还有另一个网络由几个 306 个 LSTM 组成,每个 LSTM 在第一层仅连接到一个输入通道,然后是第二个编码层 执行通道间分析,通过接收级联的输入 所有通道 LSTM 的输出向量。
谢谢
如果我没看错的话,代码应该是这样的:
def lstm_model():
hidden_units = 512 # may increase/decrease depending on capacity needed
timesteps = 600
input_dim = 306
num_classes = 10 # num of classes for ecg output
model = Sequential()
model.add(LSTM(hidden_units, input_shape=(timesteps, input_dim)))
model.add(Dense(num_classes))
adam = Adam(lr=0.001)
model.compile(loss='categorical_crossentropy', optimizer=adam, metrics=['accuracy'])
return model
def train():
xt = np.array([]) # input_data shape = (num_trials, timesteps, input_dim)
yt = np.array([]) # out_data shape = (num_trials, num_classes)
batch_size = 16
epochs = 10
model = lstm_model()
model.fit(xt, yt, epochs=epochs, batch_size=batch_size, shuffle=True)