Training a CONV network with ragged tensors

My network with take arrays of shape [X, 2000, 1], where X is variable (not batch size).
I can fit my model with input sizes of first [500,2000,1] and then [800,2000,1] consecutively and I get no errors. However, I am trying to combine the training data into one dataset so I would have a dataset with 2 batches [2, Variable, 2000, 1].
To do this I am using the following code,

batch1 = tf.RaggedTensor.from_row_splits(
values=tf.random.normal([500, 2000,1]),
row_splits=[0, 500]
batch2 = tf.RaggedTensor.from_row_splits(
values=tf.random.normal([800, 2000,1]),
row_splits=[0, 800]

Concatenate the ragged tensors

combined_data = tf.concat([batch1, batch2], axis=0)

labels =[Y1, Y2]

Create a dataset from the combined data and labels

dataset =, labels))

However I get an error when training the model using this dataset as it says it expects a input size of (None, None, 2000, 1), but it is receiving (None, 2000, 1).

It is unclear why there is a reduction in the shape of the input when I take the first data of the dataset using dataset.take(1) I get the expected shape.

Any idea?

i fixed the error above by adding
dataset = dataset.batch(1)

but now I get the following error
Failed to convert elements of tf.RaggedTensor(values=Tensor("model_average_ascans/Cast:0", shape=(None, 2000, 1), dtype=float32), row_splits=Tensor("RaggedFromVariant/RaggedTensorFromVariant:0", shape=(None,), dtype=int64)) to Tensor. Consider casting elements to a supported type. See Module: tf.dtypes  |  TensorFlow v2.13.0 for supported TF dtypes.

Does a 2d convolution not accept ragged tensors?


Welcome to the Tensorflow Forum,

No, 2D convolution does not accept ragged tensors because convolutions require tensors with fixed dimensions.

Thank you!