简体   繁体   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

I trying to convert following code to tensorflow 1.2 but I hard understand how to fixed it. 我试图将以下代码转换为tensorflow 1.2,但我很难理解如何修复它。 Thanks for your any replying. 感谢您的答复。

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)

All Input Variables: 所有输入变量:

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

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

I resolved this problem. 我解决了这个问题。

This is because cell_with_ground_truth object is come from one SamplingRNNCell function 这是因为cell_with_ground_truth对象来自一个SamplingRNNCell函数

In here, I found one line: context = tf.concat(1, [prev_output, visual_feats]), 在这里,我找到了一行:context = tf.concat(1,[prev_output,visual_feats]),

For TF 1.4, it should be fixed like this: context = tf.concat([prev_output, visual_feats], 1), 对于TF 1.4,应该这样修复:context = tf.concat([prev_output,visual_feats],1),

same with this solution 与此解决方案相同

暂无
暂无

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

相关问题 keras:TypeError:预期为int32,获取的列表包含类型为&#39;_Message&#39;的张量 - keras: TypeError: Expected int32, got list containing Tensors of type '_Message' instead CNN:TypeError:预期为int32,列表改为包含“ _Message”类型的张量 - CNN: TypeError: Expected int32, got list containing Tensors of type '_Message' instead Tensorflow Slim:TypeError:预期为 int32,得到包含“_Message”类型张量的列表 - Tensorflow Slim: TypeError: Expected int32, got list containing Tensors of type '_Message' instead TypeError:预期的float32,得到包含类型为&#39;_Message&#39;的张量的列表 - TypeError: Expected float32, got list containing Tensors of type '_Message' instead 如何在张量流存储库中找到“ tf.nn.dynamic_rnn”代码? - How do I finde the Code of “tf.nn.dynamic_rnn” in the tensorflow repository? 类型错误:预期的字符串,而是得到 0 类型的 int - TypeError: Expected String, got 0 of type int instead Keras 类型错误:应为 float32,得到<tf.tensor ..>改为“张量”类型</tf.tensor> - Keras TypeError: Expected float32, got <tf.Tensor ..>of type 'Tensor' instead seq2seq中的tf.nn.dynamic_rnn形状错误 - tf.nn.dynamic_rnn shape error in seq2seq TypeError:预期为float32,而不是类型为“ complex”的() - TypeError: Expected float32, got () of type 'complex' instead 类型错误:预期为 float32,而是得到了类型为 &#39;str&#39; 的 &#39;auto&#39; - TypeError: Expected float32, got 'auto' of type 'str' instead
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM