Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tensorflow: Py_func returns unknown shape

I have a simple question re the tf.py_func function.

I have an image tensor my_img of shape (1,224,224,3). To test py_func, I feed the tensor to a python function return_tf that should give back the same tensor (after being converted to a numpy array as per docs).

Here's the code:

def return_tf(x):
   return np.array(x)

test = tf.py_func(return_tf,[my_img],[tf.float32])

But when I checked the shape of the returned tensor called test, I get:

tf.Tensor 'PyFunc:0' shape=unknown dtype=float32

I am also unable to run eval() on the tensor, since I get the error:

AttributeError: 'list' object has no attribute 'eval'.

Anyone knows how could I fix the tensor shape of the tensor returned by tf.py_func?

like image 480
Link L Avatar asked Aug 17 '16 09:08

Link L


1 Answers

Just found a work-around.. since py_func returns a tensorflow list, I can do the ff:

test = tf.reshape(tf.concat(1, test), [ <<a shape>> ])

to get a tensor with a desired shape

like image 146
Link L Avatar answered Nov 19 '22 18:11

Link L