question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bounding box conversions fail with images of different sizes

See original GitHub issue

internally 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:closed
  • Created a year ago
  • Comments:20 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
martin-gornercommented, Nov 28, 2022

I tested. The fix looks good to me. Thanks!

1reaction
martin-gornercommented, Nov 10, 2022

Absolutely still interested. Thank you for your contributions @bhack ! I’ll have the team look at your PR asap.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found