I'm getting the shape of a TensofFlow tensor as:
(?,)
This answer says that the ?
means that the dimension is not fixed in the graph and it can vary between run calls.
What does the ?
mean in conjuction with the trailing comma?
Documentation chapter and verse would be appreciated. I find syntax very difficult to google.
shape returns a 1-D integer tensor representing the shape of input . For a scalar input, the tensor returned has a shape of (0,) and its value is the empty vector (i.e. []).
The shape is the number of elements in each dimension, e.g.: a scalar has a rank 0 and an empty shape () , a vector has rank 1 and a shape of (D0) , a matrix has rank 2 and a shape of (D0, D1) and so on.
tf. reshape(t, []) reshapes a tensor t with one element to a scalar.
Reading about the terminology you can see that shape (3, ) means you have a vector of 3 elements. And this is exactly what you provide [1, 3, 8] . Reading about shapes you would see that you want your placeholder to be a matrix of size (3 x something). So adjust either a placeholder or a feeding value.
The comma means that the dimension is represented as a 1-elem tuple instead an int.
Each tensor, when created, is by default a 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)
However, you can reshape it to get a more "whole" shape (i.e. nXm / nXmXr... dim):
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With