我想堆叠2个LSTMCell,它们在上一个时间步中,堆叠第一层的输入是堆叠的正常输入与第二层输出的串联。
这是this gist中新RNN堆栈的代码。
import keras
import numpy as np
timesteps = 60
input_dim = 64
samples = 10000
batch_size = 128
output_dim = 64
# Test data.
x_np = np.random.random((samples, timesteps, input_dim))
y_np = np.random.random((samples, output_dim))
cells = [
keras.layers.LSTMCell(output_dim), # lstm1
keras.layers.LSTMCell(output_dim), # lstm2
]
inputs = keras.Input((timesteps, input_dim))
x = keras.layers.RNN(cells)(inputs)
new_model = keras.models.Model(inputs, x)
new_model.compile(optimizer='rmsprop', loss='mse')
new_model.fit(x_np, y_np, batch_size=batch_size, epochs=4)
在Keras中这可能吗?还是我最好直接使用tensorflow?