keras-cv icon indicating copy to clipboard operation
keras-cv copied to clipboard

pad_batch_to_shape does not work with ragged bounding boxes

Open martin-gorner opened this issue 2 years ago • 2 comments

Repro code:

a = tf.ragged.constant([[[1,2,3,4,50], [1,2,3,5,32]],
                        [[0,2,3,6,66], [0,2,3,7,48], [0,2,3,8,47]]], ragged_rank=1)
print(tf.shape(a))
kcv.bounding_box.pad_batch_to_shape(a, target_shape=[2, 3, 5])

output:

/opt/conda/lib/python3.7/site-packages/keras_cv/bounding_box/pad_batch_to_shape.py in pad_batch_to_shape(bounding_boxes, target_shape, padding_values)
     46     """
     47     bounding_box_shape = tf.shape(bounding_boxes)
---> 48     if len(bounding_box_shape) != len(target_shape):
     49         raise ValueError(
     50             "Target shape should have same rank as the bounding box. "

TypeError: object of type 'DynamicRaggedShape' has no len()

Expected output:

[[[1,2,3,4,50], [1,2,3,5,32], [-1,-1,-1,-1,-1]],
 [[0,2,3,6,66], [0,2,3,7,48], [0,2,3,8,47]]]

martin-gorner avatar Oct 05 '22 12:10 martin-gorner

Unit tests for ragged bounding boxes seem to be lacking as well.

martin-gorner avatar Oct 05 '22 12:10 martin-gorner

adding the "object-detection-landing" flag because this utility functions is needed for the TPU-compatible object detection pipeline

martin-gorner avatar Oct 05 '22 12:10 martin-gorner