user11509642
user11509642

Reputation:

Looping over Ragged Tensors in Tensorflow

I wondered if there was any way too loop over Ragged Tensors, similarly to tf.map_fn. My Ragged Tensor has a different amount of rows but contains 4 points which I would like to retrieve.

The input looks as follows:

ragged_tensor[0] equals (100, 4)
ragged_tensor[1] equals (50, 4)

For now I can retrieve all of the points by looping over the first tensor inside the RaggedTensor:

test = tf.map_fn(lambda box: tf.image.crop_to_bounding_box(img, box[0], box[1], box[2], box[3]), tf.cast(boxes, tf.int32), dtype=tf.float32)

Does anyone have any experience with this, or might give me some tips&tricks? All help is appreciated.

Upvotes: 4

Views: 1126

Answers (1)

javidcf
javidcf

Reputation: 59701

This is one way to get the whole array of points:

points = tf.reshape(ragged_tensor.flat_values, [-1, 4])

Upvotes: 1

Related Questions