如何在 Python 中将 Ragged Tensor 转换为 Tensor?

Ris*_*ain 3 python arrays tensorflow tensor

我有一个参差不齐的张量,在尝试创建模型并使用 model.fit() 时,出现错误: TypeError: Failed to convert object of type <class 'tensorflow.python.ops.ragged.ragged_tensor.RaggedTensor'> to Tensor. Contents: tf.RaggedTensor(values=Tensor("Cast_1:0", shape=(None,), dtype=float32), row_splits=Tensor("RaggedFromVariant_1/RaggedTensorFromVariant:0", shape=(None,), dtype=int64)). Consider casting elements to a supported type.

这是我的数据形状的问题吗?也许数据完全?也许我需要使用稀疏或密集的张量来代替?这是我的完整回溯错误:

完整追溯

以及我的数据: XTrain 数据集

小智 6

每个RaggedTensor都有一个关联的to_tensor()方法,调用它。检查您的输入数据转换,这是创建 RaggedTensor 的地方。一些操作返回RaggedTensor