简体   繁体   中英

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

In here, I found one line: 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),

same with this solution

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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