RaggedTensor具有方法to_tensor()
和from_tensor()
。但是,如果ragged_tensor
具有嵌套维,则应用tf.RaggedTensor.from_tensor(ragged_tensor.to_tensor(), padding=0)
似乎会失败
示例:
data = tf.ragged.constant([
[[4,35,6,33], [7,2], [89,56,12]],
[[2,11], [9]]
])
tf.RaggedTensor.from_tensor(data.to_tensor(), padding=0)
返回错误
Traceback (most recent call last):
File "./src/tppmodel.py", line 34, in <module>
tf.RaggedTensor.from_tensor(data.to_tensor(), padding=0)
File "/opt/conda/lib/python3.8/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/opt/conda/lib/python3.8/site-packages/tensorflow/python/framework/tensor_shape.py", line 1307, in assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes () and (4,) are incompatible
预期值
tf.RaggedTensor.from_tensor(data.to_tensor(),..., padding=0) = data
1条答案
按热度按时间insrf1ej1#
我自己可能已经找到了答案。以防万一的帖子对某些人很有用:不使用padding参数,而是传递原始Tensor的嵌套行长度
第一个