TensorFlow shape(?,)是什么意思?

Tom*_*ale 6 python tensorflow

我得到一个TensofFlow张量的形状为:

(?,)

这个答案说的?意思是维在图中不是固定的,并且在运行调用之间可以变化。

?与尾随的逗号结合意味着什么?

文档章节和经文将不胜感激。我发现语法非常难以使用Google。

CIs*_*ies 6

逗号表示维度表示为1-elem 元组而不是 int。

每个张量在创建时默认是一个 n-dim:

import tensorflow as tf
t = tf.constant([1, 1, 1])
s = tf.constant([[1, 1, 1],[2,2,2]])

print("0) ", tf.shape(t))
print("1) ", tf.shape(s))

0)  Tensor("Shape_28:0", shape=(1,), dtype=int32)
1)  Tensor("Shape_29:0", shape=(2,), dtype=int32)
Run Code Online (Sandbox Code Playgroud)

但是,您可以重塑它以获得更“完整”的形状(即 n X m / n X m X r ...暗淡):

print("2) ", tf.reshape(t, [3,1]))
print("3) ", tf.reshape(s, [2,3]))

2)  Tensor("Reshape_12:0", shape=(3, 1), dtype=int32)
3)  Tensor("Reshape_13:0", shape=(2, 3), dtype=int32)
Run Code Online (Sandbox Code Playgroud)