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
?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With