goluhaque
goluhaque

Reputation: 571

Tensorflow convert_to_tensor TypeError: List of Tensors when single Tensor expected

I am getting the following error when executing the code below. rnn.rnn() returns a list of tensors. Error is on the convert_to_tensor line.

TypeError: List of Tensors when single Tensor expected

outputs, _states = rnn.rnn(lstm, X_split, initial_state=init_state)
output_tensor = tf.convert_to_tensor(outputs)

When I also initialized the dtype argument to tf.float32

output_tensor = tf.convert_to_tensor(outputs, dtype=tf.float32)

I got the following error on the same line:

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

What is the cause of these errors? I want my final output to be a tensor containing tensors.

EDIT: I checked the DType of the individual tensors of the list. All of them are of type float32. What could be the cause of this error now?

Upvotes: 4

Views: 5170

Answers (1)

goluhaque
goluhaque

Reputation: 571

I should have used tf.pack() which is present for just this purpose: converting a list of N dimensioned tensors to a N+1 dimensioned vector. Quite straightforward.

Upvotes: 4

Related Questions