Tensorflow 为什么;tf.nn.双向“动态”;有一个;“不兼容操作”;在TPU上,何时检查张力板?

Tensorflow 为什么;tf.nn.双向“动态”;有一个;“不兼容操作”;在TPU上,何时检查张力板?,tensorflow,google-cloud-tpu,Tensorflow,Google Cloud Tpu,我在检查双向rnn的“TPU兼容性”时遇到问题。TensorBoard告诉我序列长度向量的反转操作在TPU上不兼容。我不知道为什么 我的简单代码: X_batch = np.array([ [[0., 1., 2.], [8., 2., 1.], [9., 8., 7.]], [[3., 4., 5.], [9., 7., 4.], [0., 0., 0.]], [[6., 7

我在检查双向rnn的“TPU兼容性”时遇到问题。TensorBoard告诉我序列长度向量的反转操作在TPU上不兼容。我不知道为什么

我的简单代码:

X_batch = np.array([
                    [[0., 1., 2.], [8., 2., 1.], [9., 8., 7.]],
                    [[3., 4., 5.], [9., 7., 4.], [0., 0., 0.]],
                    [[6., 7., 8.], [3., 6., 7.], [6., 5., 4.]],
                    [[9., 0., 1.], [0., 0., 0.], [0., 0., 0.]]
                   ])
seq_length_batch = np.array([3, 2, 3, 1])

batch = 4
n_steps = 3
input_size = 3
inputs = tf.placeholder(tf.float32, [batch, n_steps, input_size])
seq_len = tf.placeholder(tf.int32, [None])

def biLSTM(inputs, seq_len, n_hidden, batch_size):
    lstm_fw = tf.nn.rnn_cell.LSTMCell(n_hidden, state_is_tuple=True)
    lstm_bw = tf.nn.rnn_cell.LSTMCell(n_hidden, state_is_tuple=True)

    _initial_state_fw = lstm_fw.zero_state(batch_size, tf.float32)
    _initial_state_bw = lstm_bw.zero_state(batch_size, tf.float32)

    output, _states = tf.nn.bidirectional_dynamic_rnn(lstm_fw, lstm_bw, inputs,
                                   initial_state_fw=_initial_state_fw,
                                   initial_state_bw=_initial_state_bw,
                                   sequence_length=seq_len)

    final_outputs = tf.concat([output[0], output[1]], 2)
    return final_outputs

biLSTM_model = biLSTM(inputs, seq_len, 4, batch)

with tf.Session() as sess:
    check_write = tf.summary.FileWriter('../test_tensorboard', sess.graph)
    init = tf.global_variables_initializer()
    init.run()
    print(sess.run(biLSTM_model, feed_dict={inputs: X_batch,
                                           seq_len: seq_length_batch}))
TensorBoard屏幕截图:


  • 我也有同样的问题,我甚至在TPU上实现了它,但遇到了无法展开的障碍,因为它包含一个条件while循环(循环直到到达输入的末尾)


    一种可能的修复方法是将输入数据填充为恒定长度,并将条件while循环更改为具有静态长度的循环

    TensorFlow的哪个版本?它是最近才实现的(至少应该是1.7+版本),但不是这样。