将可变大小的 numpy 数组转换为 Tensorflow 张量

Nit*_*hah 5 python numpy tensorflow tensorflow2.0

我正在尝试 Tensorflow 2.0 alpha 预览版并正在测试 Eager execution 。我的疑问是,如果您在中间有一个可变大小的 numpy 数组,例如

input.shape
(10,)

input[0].shape
(109, 16)

input[1].shape
(266, 16)
Run Code Online (Sandbox Code Playgroud)

等等数组的其余部分,如何急切地将它们转换为张量。

当我尝试

tf.convert_to_tensor(input)
Run Code Online (Sandbox Code Playgroud)

或者

tf.Variable(input)
Run Code Online (Sandbox Code Playgroud)

我得到

ValueError:无法将 numpy ndarray 转换为张量(无法以字节形式获取元素。)。

转换每个子数组有效,但由于子数组大小不同,tf.stack 不起作用。

任何帮助或建议?

Hey*_*his 3

这也急切地发生在我身上。看着这里的文档,我最终尝试了

tf.convert_to_tensor(input, dtype=tf.float32)
Run Code Online (Sandbox Code Playgroud)

这对我有用。