多次使用tf.nn.dynamic_rnn(),维度必须相等,否则会发生错误

2024-09-23 04:30:37 发布

您现在位置:Python中文网/ 问答频道 /正文

当我在代码中多次使用tf.nn.dynamic_rnn()

ValueError: Dimensions must be equal, but are 80 and 90 for '..scope1/rnn/while/gru_cell/MatMul_4' (op: 'MatMul') with input shapes: [50,80], [90,80].'

发生

我的代码片段是:

gru = tf.contrib.rnn.GRUCell(d)
with tf.variable_scope('scope1'):
    _, outputs_1 = tf.nn.dynamic_rnn(gru, inputs, dtype=tf.float32) # inputs:[N, L, V]
with tf.variable_scope('scope2'):
    outputs_2 = somefunc(outputs_1)
with tf.variable_scope('scope3'):
    _, outputs_3 = tf.nn.dynamic_rnn(gru, outputs_2, dtype=tf.float32) outputs_2:[N, L, d]

如果我将d设置为不等于V,则运行代码会抛出上述错误。如果将d设置为等于V,则没有问题。为什么?两个tf.nn.dynamic\u rnn()不是直接堆叠的。它们应该相互独立


Tags: 代码tfwithdynamicnnoutputsvariablescope