繁体   English   中英

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

[英]When I run “tf.nn.dynamic_rnn”, I got TypeError: Expected int32, got list containing Tensors of type '_Message' instead

我试图将以下代码转换为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>))

错误消息:

---------------------------------------------------------------------------
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.

我解决了这个问题。

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

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

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

与此解决方案相同

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM