该的文件
tf.nn.dynamic_rnn中指出:
inputs:RNN输入。如果是time_major == False(默认值),则它必须是shape:的张量[batch_size,max_time, ...],或此类元素的嵌套元组。
在您的情况下,这意味着输入的形状应为
[batch_size, 10,2]。无需一次训练所有4000个序列,而是
batch_size在每次训练迭代中仅使用其中的许多序列。类似于以下内容的东西应该起作用(为清楚起见,添加了重新塑形):
batch_size = 32# batch_size sequences of length 10 with 2 values for each timestepinput = get_batch(X, batch_size).reshape([batch_size, 10, 2])# Create LSTM cell with state size 256. Could also use GRUCell, ...# Note: state_is_tuple=False is deprecated;# the option might be completely removed in the futurecell = tf.nn.rnn_cell.LSTMCell(256, state_is_tuple=True)outputs, state = tf.nn.dynamic_rnn(cell, input, sequence_length=[10]*batch_size, dtype=tf.float32)
从文档开始,
outputs将具有形状
[batch_size,10,256],即每个时间步长一个256输出。
state将是一个形状的元组
[batch_size,256]。您可以据此预测最终值(每个序列一个):
predictions = tf.contrib.layers.fully_connected(state.h, num_outputs=1, activation_fn=None)loss = get_loss(get_batch(Y).reshape([batch_size, 1]), predictions)
形状为
outputs和的数字256
state由
cell.output_size和决定。
cell.state_size。在创建
LSTMCell上述内容时,它们是相同的。另请参阅LSTMCell文档。



