bounding box conversions fail with images of different sizes
See original GitHub issueinternally b/242193874
repro code:
images = tf.ragged.constant([np.ones(shape=[20,30,3]), # 2 images
np.ones(shape=[25,15,3])], ragged_rank=2)
print("Images shape:", images.shape)
boxes = tf.ragged.constant([[[3,5,15,25], [10,2,12,4], [1,9,7,19]], # 3 boxes
[[1,10,24,14], [5,6,14,16]]], ragged_rank=1) # 2 boxes
print("Boxes shape:", boxes.shape)
# boxes originally in "xyxy" format, converting to "rel_xyxy"
kcv.bounding_box.convert_format(boxes, source="xywh", target="rel_xyxy", images=images)
output is :
Images shape: (2, None, None, 3)
Boxes shape: (2, None, 4)
but the bbox conversion fails with error:
ValueError: Index 1 is not uniform
Looking at the code, a single width and a single height are extracted from the parameter “images” which is wrong. Multiple images can have multiple sizes:
def _xyxy_to_rel_xyxy(boxes, images=None):
if images is None:
raise RequiresImagesException()
shape = tf.shape(images)
==> height, width = shape[1], shape[2]
height, width = tf.cast(height, boxes.dtype), tf.cast(width, boxes.dtype)
left, top, right, bottom, rest = tf.split(
boxes, [1, 1, 1, 1, boxes.shape[-1] - 4], axis=-1
)
left, right = left / width, right / width
top, bottom = top / height, bottom / height
return tf.concat(
[left, top, right, bottom, rest],
axis=-1,
)
Issue Analytics
- State:
- Created a year ago
- Comments:20 (13 by maintainers)
Top Results From Across the Web
including tif/eps/pdf fails due to bounding box/dimensions - TeX
One of the reasons why pdfTeX doesn't support TIFF image inclusion is that there are really many different TIFF formats. So a conversion...
Read more >Clipped object bounding box too big (#7161) - Inkscape - GitLab
A clipped object (e.g. image) has a bounding box the same size as the original object, when it should only encompass the smaller, ......
Read more >Bounding Box from VNDetectRectangleRequest is not correct ...
First let's look at boundingBox , which is a "normalized" rectangle. Apple says. The coordinates are normalized to the dimensions of the ...
Read more >ValueError: All bounding boxes should have positive height ...
The answer from @oke-aditya is correct. You are probably passing to the model bounding boxes in the format [xmin, ymin, width, height] ,...
Read more >Bounding Box Prediction from Scratch using PyTorch
Since training a computer vision model needs images to be of the same size, we need to resize our images and their corresponding...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I tested. The fix looks good to me. Thanks!
Absolutely still interested. Thank you for your contributions @bhack ! I’ll have the team look at your PR asap.