Tensorflow:Py_func返回未知形状

Lin*_*k L 6 python numpy tensorflow

我有一个简单的问题是tf.py_func功能.

我有一个my_img形状张量的形状(1,224,224,3).为了测试py_func,我将张量提供给python函数return_tf,该函数应该返回相同的张量(根据文档转换为numpy数组之后).

这是代码:

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

test = tf.py_func(return_tf,[my_img],[tf.float32])
Run Code Online (Sandbox Code Playgroud)

但当我检查返回张量的形状时test,我得到:

tf.Tensor 'PyFunc:0' shape=unknown dtype=float32
Run Code Online (Sandbox Code Playgroud)

我也无法eval()在张量上运行,因为我收到了错误:

AttributeError: 'list' object has no attribute 'eval'.
Run Code Online (Sandbox Code Playgroud)

任何人都知道如何修复由张量返回的张量形状tf.py_func

Lin*_*k L 5

刚发现一个解决方法..因为py_func返回张量流列表,我可以做ff:

test = tf.reshape(tf.concat(1, test), [ <<a shape>> ])
Run Code Online (Sandbox Code Playgroud)

获得具有所需形状的张量