Semplicemente, utilizzare tensor.shape
per ottenere la forma statica :
In [102]: a = tf.placeholder(tf.float32, [None, 128])
# returns [None, 128]
In [103]: a.shape.as_list()
Out[103]: [None, 128]
considerando che, per ottenere la forma dinamica , utilizzare tf.shape()
:
dynamic_shape = tf.shape(a)
È possibile anche ottenere la forma come ci si in NumPy con your_tensor.shape
come nel seguente esempio.
In [11]: tensr = tf.constant([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6]])
In [12]: tensr.shape
Out[12]: TensorShape([Dimension(2), Dimension(5)])
In [13]: list(tensr.shape)
Out[13]: [Dimension(2), Dimension(5)]
In [16]: print(tensr.shape)
(2, 5)
Inoltre, questo esempio, per tensori che può essere eval
uated.
In [33]: tf.shape(tensr).eval().tolist()
Out[33]: [2, 5]
ho trovato [questo] (https://stackoverflow.com/a/41771268/1358091) rispondere molto utile per analizzare la forma di un tensore, nonostante non sia quella accettata. –