DavidBankom DavidBankom - 19 days ago 15
Python Question

Tensorflow. Converting unknown dimension size of a tensor to int

Assume we have

a = tf.placeholder(tf.float32, shape=(None, 3072))
b = a.get_shape()[0]


How can I convert b such that I can use it in further calculations, e.g. for given tensor T I will be able to create a new one, sth like

newT = T / b

Answer

You have to use a Graph operation:

a = tf.placeholder(tf.float32, shape=(None, 3072))
b = tf.shape(a)[0]

returns

<tf.Tensor 'strided_slice:0' shape=() dtype=int32>

while b = a.get_shape()[0] returns

Dimension(None)