Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: List of Tensors when single Tensor expected - when using const with tf.random_normal

I have the following TensorFlow code:

tf.constant(tf.random_normal([time_step, batch_size], -1, 1))

I am getting TypeError: List of Tensors when single Tensor expected. Could you tell me what is wrong with the code?

like image 306
vijendra rana Avatar asked May 26 '17 17:05

vijendra rana


2 Answers

Someone else has answered this question on another thread.

Essentially, tf.constant() takes a NumPy array as an argument or some sort of array or just a value.

tf.random_normal() returns a Tensor which cannot be an argument to tf.constant().

To fix this, use tf.Variable() instead of tf.constant().

See the answer from the link. The person explains it better.

like image 50
Izzudin Hafiz Avatar answered Oct 21 '22 22:10

Izzudin Hafiz


tf.constant is supposed to have a constant argument - value. Here value can be a constant value or a list of values of type dtype. You can't create a constant tensor that has another tensor as its value.

like image 2
Huy Vo Avatar answered Oct 21 '22 22:10

Huy Vo