0

As indicating in many TF docs, the graph begin to build only when we create the sess and execute the sess.run() method.

Just now, I tested that:

X = tf.placeholder(dtype=tf.float32, shape=[100,28,28,1])
W = tf.get_variable(...)
Y = tf.matmul(X,W)
print(Y.get_shape()[0].value)

As see in this code, it outputs the particular the shape value of Y even I did not t create the session instance.

How to understand? Thank you!

Kevin Sun
  • 452
  • 4
  • 14
  • You don't need to calculate the matrix multiplication to determine the shape of the result probably would be one of the reasons. For instance a 3X2 tensor times a 2X5 matrix will always end up with a 3X5 matrix, you can predetermine this without the actual calculation. – Psidom Aug 24 '17 at 01:03
  • Just an example – Kevin Sun Aug 24 '17 at 03:21

1 Answers1

5

There's "static shape" and "dynamic shape", get_shape() is static and only needs graph, tf.shape is dynamic and needs session -- How to understand static shape and dynamic shape in TensorFlow?

Yaroslav Bulatov
  • 57,332
  • 22
  • 139
  • 197