Skip to main content

Placeholder Shape - Tensorflow

 Placeholder can be defined as:

tf.placeholder(tf.float32, shape=(1, 16, 64, 64, 1), name='real_node_a') 

or

tf.placeholder(tf.float32, shape=(None, None, None, None, None), name='real_node_a') 


If you want to read shape from None, use:

h      = tf.shape(inputs)[2]

w      = tf.shape(inputs)[3]


If you want to read shape from numbers, use:

nb, nt = inputs.get_shape().as_list()[0:2]


sometimes some nodes in the graph require integer input instead of None, in that case you must hard code placeholder with numbers and use get_shape

None provides more flexibility but might not work with all.