Reputation: 45
I have a placeholder which shape is [None, dimension], "None" means batch size. I want to get the real shape of "None".
I try two methods when I build model:
First, x.get_shape() and get shape as [Dimension(None), Dimension(128)]
Second, x.shape and get shape as [Dimension(None), Dimension(128)]
And what I want is the real shape, for example, when the batch size is 100 in this round, I would like to get [Dimension(100), Dimension(128)].
How do I get the dynamic input shape?
Upvotes: 3
Views: 2198
Reputation: 1742
I believe tf.shape
is what you are looking for.
tf.shape(x)
can get the shape while session is running.
The full example is below:
import tensorflow as tf
a = tf.ones([3,4])
b = tf.shape(a)
sess=tf.Session()
print(b.eval(session=sess))
You can also use b
to init new variables.
Upvotes: 2