2017-10-12 93 views
1

計算兩個張量值,並嘗試創建動態形狀的張量。 E是張量變量的切片,labelLen_l是一個佔位符,tensorval1和tensorval2是維的張量1Tensorflow:使用動態計算張量填充張量

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)

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

我試圖計算NUM1 + NUM2 + NUM3和因此它們的尺寸應該匹配。任何建議來實現它?

回答

1

您可以使用tf.shape來獲得作爲張量類型的張量形狀。

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

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

應該是:

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