简体   繁体   中英

Tensorflow: Fill the tensor with dynamically computed value tensor

The two tensor values are computed and I tried to create the tensor of dynamic shape. E is a slice of a tensor variable, labelLen_l is a placeholder, tensorval1 and tensorval2 are tensors of dimension 1.

num1 = tf.reduce_sum(tf.eye(labelLen_l, dtype=tf.float64)*E, 1) num2 = tf.fill(num1.shape, tensor_val1) num3 = tf.fill(num1.shape, tensor_val2)

It says ValueError: Tried to convert 'dims' to a tensor and failed. Error: Cannot convert a partially known TensorShape to a Tensor: <unknown> ValueError: Tried to convert 'dims' to a tensor and failed. Error: Cannot convert a partially known TensorShape to a Tensor: <unknown>

I am trying to compute num1 + num2 + num3 and hence their dimension should match. Any suggestions to achieve it?

You can use tf.shape in order to get the tensor shape as a tensor type.

num2 = tf.fill(num1.shape, tensor_val1)

num3 = tf.fill(num1.shape, tensor_val2)

should be:

num2 = tf.fill(tf.shape(num1), tensor_val1)
num3 = tf.fill(tf.shape(num1), tensor_val2)

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