计算两个张量值,我试图创建动态形状的张量。 E是张量变量的切片,labelLen_l是占位符,tensorval1和tensorval2是维度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)
它说ValueError: Tried to convert 'dims' to a tensor and failed. Error: Cannot convert a partially known TensorShape to a Tensor: <unknown>
我正在尝试计算num1 + num2 + num3,因此它们的尺寸应匹配。有任何建议可以实现吗?
答案 0 :(得分: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)