当我运行“tf.nn.dynamic_rnn”时,我得到TypeError:期望的int32,得到包含类型为'_Message'的张量的列表

时间:2017-07-11 02:21:34

标签: python python-2.7 tensorflow

我尝试将以下代码转换为tensorflow 1.2,但我很难理解如何修复它。感谢您的回复。

out_gt, controller_final_state_gt = tf.nn.dynamic_rnn(
cell=cell_with_ground_truth, 
inputs=rnn_inputs_with_ground_truth, 
sequence_length=[SEQ_LEN]*BATCH_SIZE, 
initial_state=controller_initial_state_gt, 
dtype=tf.float32,
swap_memory=True,
time_major=False)

所有输入变量:

cell_with_ground_truth:<__main__.SamplingRNNCell object at 0x7f3f88383250>
rnn_inputs_with_ground_truth:(<tf.Tensor 'dropout/mul:0' shape=(4, 10, 128) dtype=float32>, <tf.Tensor 'div:0' shape=(4, 10, 3) dtype=float32>)
[SEQ_LEN]:[10]
BATCH_SIZE:4
controller_initial_state_gt:(<tf.Tensor 'Identity_3:0' shape=(4, 3) dtype=float32>, LSTMStateTuple(c=<tf.Tensor 'Identity_4:0' shape=(4, 32) dtype=float32>, h=<tf.Tensor 'Identity_5:0' shape=(4, 32) dtype=float32>))

错误Messgae:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-9-1911ca77ee35> in <module>()
     53         out_gt, controller_final_state_gt = tf.nn.dynamic_rnn(cell=cell_with_ground_truth, inputs=rnn_inputs_with_ground_truth, 
     54                           sequence_length=[SEQ_LEN]*BATCH_SIZE, initial_state=controller_initial_state_gt, dtype=tf.float32,
---> 55                           swap_memory=True, time_major=False)
     56 
     57     with tf.variable_scope("predictor", reuse=True):

/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/rnn.pyc in dynamic_rnn(cell, inputs, sequence_length, initial_state, dtype, parallel_iterations, swap_memory, time_major, scope)
    572         swap_memory=swap_memory,
    573         sequence_length=sequence_length,
--> 574         dtype=dtype)
    575 
    576     # Outputs of _dynamic_rnn_loop are always shaped [time, batch, depth].

/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/tensor_util.pyc in _AssertCompatible(values, dtype)
    300     else:
    301       raise TypeError("Expected %s, got %s of type '%s' instead." %
--> 302                       (dtype.name, repr(mismatch), type(mismatch).__name__))
    303 
    304 

TypeError: Expected int32, got list containing Tensors of type '_Message' instead.

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。

这是因为cell_with_ground_truth对象来自一个SamplingRNNCell函数

在这里,我发现了一行: context = tf.concat(1,[prev_output,visual_feats]),

对于TF 1.4,它应该像这样修复: context = tf.concat([prev_output,visual_feats],1),

与此solution

相同