TensorFlow LSTM用于4-D张量

时间:2018-03-06 22:24:40

标签: python tensorflow lstm

如果我有一个形状为[None, None, None, 10]的输入,我想做类似以下的事情,

input = tf.placeholder([None, None, None, 10], dtype=tf.float32)
length = tf.placeholder([None, None], dtype=tf.int32)
cell = tf.nn.rnn_cell.BasicLSTMCell(num_units=10)
def fn(inp): 
  output, _ = tf.dynamic_rnn(cell, inp[0], sequence_length=inp[1])
  return output

tf.map_fn(fn, (input, length), dtype=tf.float32)

但它不适用于自动梯度推导,它会产生如下错误,

Cannot use 'XXX' as input to 'gradients/YYY/while/TensorArrayWrite/TensorArrayWriteV3_grad/TensorArrayReadV3/f_acc' 
because 'XXX' is in a while loop.

这是TensorFlow的限制,它无法处理嵌套的while_loopdynamic_rnnmap_fn在场景后面运行while_loop,或者有办法解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

TensorFlow 1.6修复了此问题