1

It's not allowed to fetch the values of tensors created inside a conditional or while loop in tensorflow. I've tried tf.shape(t) Session.run() and Tensor.eval(), but all of them occur errors.

Is it possible to get the shape of tensor, which is determined after graph execution?

For example, here is a while_loop:

inputs = tf.placeholder(tf.float32,shape=(None,32,32))
i = tf.placeholder(dtype='int32')

def loop_body(i,inputs):
    x = tf.add(i, 1, name = 'add1')   
    y = tf.add(inputs,1)
    return x,y
output = tf.while_loop(lambda i,inputs: tf.less(i, 10), loop_body, [i,inputs])

How can I get the shape of tensor while/add1:0 after input placeholder is feed?

Canran
  • 11
  • 1
  • The [`tf.shape()` operation](https://stackoverflow.com/a/37096395/3574081) is the proper way to get the dynamic shape of a tensor. Please share the code and what error you were seeing when you tried that. – mrry Jan 08 '18 at 15:57

0 Answers0