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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.