如何将不规则张量转换为 Python 中的张量?

How to Convert Ragged Tensor to Tensor in Python?

我的张量参差不齐,在尝试创建模型并使用 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.

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

还有我的数据:

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