Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert Ragged Tensor to Tensor in Python?

I have a ragged tensor, and upon trying to create a model, and use model.fit(), I get an error: 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.

Is this an issue with the shape of my data? Perhaps the data altogether? Maybe I need to use a sparse or dense tensor instead? Here is my full traceback error:

Full Traceback

As well as my data: XTrain dataset

like image 820
Rishab Jain Avatar asked May 12 '26 20:05

Rishab Jain


1 Answers

Every RaggedTensor has an associated to_tensor() method, call that. Check your input data transformations, that is where the RaggedTensor is getting created. Some ops return RaggedTensor.

like image 111
Abhishek Verma Avatar answered May 14 '26 18:05

Abhishek Verma