【发布时间】:2019-10-30 07:39:53
【问题描述】:
我是 tensorflow 的新手,我有下面这样的张量,
a = tf.constant([[1, 2, 3], [4, 5, 6]])
a.shape 的输出是
TensorShape([Dimension(2), Dimension(3)])
对于我的计算过程,我想将张量重塑为 (?, 2, 3)
我无法将其重塑为所需的格式。
我试过了,
tf.reshape(a, [-1, 2, 3])
但它会返回,
<tf.Tensor 'Reshape_18:0' shape=(1, 2, 3) dtype=int32> # 1 has to be replaced by ?
我进一步尝试,
tf.reshape(a, [-1, -1, 2, 3])
它返回,
<tf.Tensor 'Reshape_19:0' shape=(?, ?, 2, 3) dtype=int32> # two ? are there
如何获得想要的结果?
对不起,如果这听起来很简单的问题。
【问题讨论】:
-
还有什么问题?任何期望形状
(?, 2, 3)的东西也应该接受形状(1, 2, 3)。你有例外吗? -
是的。我得到一个例外,说张量的外部尺寸为 1 并且应该是 None 。这是 tensorflow 服务模型的一部分,它期望最外层维度为无,因此它可以提供批量输出。如果是一个,那么它只能提供一个输出。
标签: python python-3.x tensorflow